Bug->Doc #18147 [Opn->Ana]: Wrong regex in variablenameRegExp
| From: | borz_off at cs dot msu dot su | Date: | Wed, 14 Mar 2012 11:01:47 +0000 |
| Subject: | Bug->Doc #18147 [Opn->Ana]: Wrong regex in variablenameRegExp | ||
| References: | 1 | Groups: | php.pear.bugs |
| Request: | Send a blank email to pear-bugs+get-8391@lists.php.net to get a copy of this message | ||
Edit report at https://pear.php.net/bugs/bug.php?id=18147&edit=1
ID: 18147
Updated by: borz_off@cs.msu.su
Reported By: martin dot edlman at gmail dot com
Summary: Wrong regex in variablenameRegExp
-Status: Open
+Status: Analyzed
-Type: Bug
+Type: Documentation Problem
Package: HTML_Template_Sigma
Operating System: Linux, Windows
Package Version: 1.2.0
PHP Version: 5.2.9
-Assigned To:
+Assigned To: avb
Roadmap Versions:
New Comment:
-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.
Previous Comments:
------------------------------------------------------------------------
[2010-12-27 07:43:08] 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>
------------------------------------------------------------------------
--
Edit this bug report at https://pear.php.net/bugs/bug.php?id=18147&edit=1