From c6c1851c6ee8b148a4a81bc784347e70929ff4d1 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 23 Feb 2023 14:03:13 -0800 Subject: [PATCH] Smarty - {htxt} blocks should not be evaluated unless needed --- CRM/Core/Smarty.php | 1 + .../Smarty/plugins/prefilter.htxtFilter.php | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 CRM/Core/Smarty/plugins/prefilter.htxtFilter.php diff --git a/CRM/Core/Smarty.php b/CRM/Core/Smarty.php index 41a7020575..09991fb275 100644 --- a/CRM/Core/Smarty.php +++ b/CRM/Core/Smarty.php @@ -144,6 +144,7 @@ class CRM_Core_Smarty extends Smarty { $this->default_modifiers[] = 'escape:"htmlall"'; } $this->load_filter('pre', 'resetExtScope'); + $this->load_filter('pre', 'htxtFilter'); $this->assign('crmPermissions', new CRM_Core_Smarty_Permissions()); diff --git a/CRM/Core/Smarty/plugins/prefilter.htxtFilter.php b/CRM/Core/Smarty/plugins/prefilter.htxtFilter.php new file mode 100644 index 0000000000..1a2a56a085 --- /dev/null +++ b/CRM/Core/Smarty/plugins/prefilter.htxtFilter.php @@ -0,0 +1,36 @@ + function ($m) use (&$htxts) { + $htxts++; + return sprintf('{if $id == %s}%s', $m[1], $m[0]); + }, + ';\{/htxt\};' => function($m) use (&$_htxts) { + $_htxts++; + return '{/htxt}{/if}'; + }, + ], $tpl_source); + + if ($htxts !== $_htxts) { + throw new \RuntimeException(sprintf('Invalid {htxt} tag. Wrapped %d opening-tags and %d closing-tags.', $htxts, $_htxts)); + } + + return $result; +} -- 2.25.1