Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.3.0

Doc Bug #18147 Wrong regex in variablenameRegExp
Submitted: 2010-12-27 12:43 UTC
From: edlman Assigned: avb
Status: Closed Package: HTML_Template_Sigma (version 1.2.0)
PHP Version: 5.2.9 OS: Linux, Windows
Roadmaps: (Not assigned)    
Subscription  


 [2010-12-27 12:43 UTC] edlman (Martin Edlman)
Description: ------------ I have encountered a problem when using Javascript with regex in a template. See example below. The problem is with {4} which matches $variablenameRegExp defined in Sigma.php (line 166) and is removed as unused variable, so the javascript regex passed to a browser looks this way /^\d-\d{1,2}-\d{1,2}$/ which is wrong. There are several fixex. 1. don't remove unused variables, this is not the best way. 2. write the regex as /^\d{4,4}-\d{1,2}-\d{1,2}$/ which won't pass the $variablenameRegExp. This makes the code a little bit irrational. 3. fix the $variablenameRegExp definition so the variable name must begin with a letter or underscore. This is the best way in my opinion. var $variablenameRegExp = '[A-Za-z_][0-9A-Za-z\._-]*'; Could you fix it in next version of Sigma.php? Test script: --------------- <script type="text/javascript> function checkdate(d) { if(/^\d{4}-\d{1,2}-\d{1,2}$/.test(d)) { return true; } else { return false; } } </script> Expected result: ---------------- <script type="text/javascript> function checkdate(d) { if(/^\d{4}-\d{1,2}-\d{1,2}$/.test(d)) { return true; } else { return false; } } </script> Actual result: -------------- <script type="text/javascript> function checkdate(d) { if(/^\d-\d{1,2}-\d{1,2}$/.test(d)) { return true; } else { return false; } } </script>

Comments

 [2012-03-14 15:01 UTC] avb (Alexey Borzov)
-Status: Open +Status: Analyzed -Type: Bug +Type: Documentation Problem -Assigned To: +Assigned To: avb
Changing the default regexp (even if the current one a bit irrational) can break the package for some users, so this is not an option. However, it is possible to create a subclass of HTML_Template_Sigma and change (some) properties like $variablenameRegExp defining the template syntax. This should be documented in "Template syntax" manual chapter.
 [2014-01-15 18:36 UTC] avb (Alexey Borzov)
-Status: Analyzed +Status: Closed
Added a section to the "Template syntax" chapter.