Allow parenthesis before hasPerm in smarty templates
authorNicolas Iooss <nicolas.iooss_git@polytechnique.org>
Mon, 26 May 2014 21:14:00 +0000 (23:14 +0200)
committerNicolas Iooss <nicolas.iooss_git@polytechnique.org>
Sun, 1 Jun 2014 19:27:29 +0000 (21:27 +0200)
In smarty templates, this syntax works fine:

    {if !hasPerm('directory_private') && other_test() }

... but not this one:

    {if (!hasPerm('directory_private') || test1()) && test2()}

... because the regexp which handle hasPerm "function" in smarty does
not support parenthesis.

Fix this bug by explicitly allowing space and open parenthesis before
hasPerm().

ChangeLog
classes/plpage.php

index 9ae2a69..29e17df 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,11 @@
 ================================================================================
+VERSION 1.1.13                                                        XX XX XXXX
+
+Bugs:
+
+    * Allow parenthesis before hasPerm() in templates                       -IOS
+
+================================================================================
 VERSION 1.1.12                                                        08 03 2014
 
 Bugs:
index b79fa1c..30c2a82 100644 (file)
@@ -525,10 +525,10 @@ function core_include($source, $smarty)
 function if_rewrites($source, $smarty)
 {
     $perms = 'isset($smarty.session.user|smarty:nodefaults) && $smarty.session.user';
-    return preg_replace(array('/\{(else)?if([^}]*) (\!?)hasPerms?\(([^)]+)\)([^}]*)\}/',
-                              '/\{(else)?if([^}]*) (\!?)t\(([^)]+)\)([^}]*)\}/'),
-                        array('{\1if\2 \3(' . $perms . '->checkPerms(\4))\5}',
-                              '{\1if\2 \3(isset(\4|smarty:nodefaults) && (\4|smarty:nodefaults))\5}'),
+    return preg_replace(array('/\{(else)?if([^}]*)([ \(]\!?)hasPerms?\(([^)]+)\)([^}]*)\}/',
+                              '/\{(else)?if([^}]*)([ \(]\!?)t\(([^)]+)\)([^}]*)\}/'),
+                        array('{\1if\2\3(' . $perms . '->checkPerms(\4))\5}',
+                              '{\1if\2\3(isset(\4|smarty:nodefaults) && (\4|smarty:nodefaults))\5}'),
                         $source);
 }