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

Request #15993 Collisions between template variable names and javascript
Submitted: 2009-03-08 21:48 UTC
From: thefsb Assigned: cweiske
Status: Closed Package: HTML_Template_PHPLIB (version 1.4.0)
PHP Version: 5.2.5 OS: OS X 10.5 / FreeBSD 7.1
Roadmaps: (Not assigned)    
Subscription  


 [2009-03-08 21:48 UTC] thefsb (tom worster)
Description: ------------ Problems sometimes arise if javascript in a template string matches the pattern for a replacement, e.g.: <a href="javascript:my_fn({firstkey:12,secondkey:'String'})"> var myRe = new RegExp("\d{1,5}"); Existing workarounds, e.g. setUnknowns('keep'), are not always convenient. Another possibility is to allow the user to expand the set of illegal characters in template variable names. Here is a diff of a possible implementation: 79a80,81 > var $illegals = ''; > 213a216,220 > function setIllegals($illegals = '') > { > $this->illegals = $illegals; > } > 506c513 < preg_match_all("/{([^ \t\r\n}]+)}/", $this->getVar($handle), $m); --- > preg_match_all("/{([^ \t\r\n}$this->illegals]+)}/", $this- >getVar($handle), $m); 538c545 < $str = preg_replace('/{[^ \t\r\n}]+}/', '', $str); --- > $str = preg_replace("/{[^ \t\r\n}$this->illegals]+}/", '', $str); 542c549 < $str = preg_replace('/{([^ \t\r\n}]+)}/', --- > $str = preg_replace("/{([^ \t\r\n}$this->illegals]+)}/", In the two examples above, $t->setIllegals(',') would work.

Comments

 [2009-08-19 18:09 UTC] thefsb (tom worster)
on second thoughts, the line in setIllegals() in my proposed changes should probably be: $this->illegals = preg_quote($illegals, '/');
 [2009-09-19 12:00 UTC] cweiske (Christian Weiske)
-Status: Open +Status: Closed -Assigned To: +Assigned To: cweiske
This bug has been fixed in SVN. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better. Will be in 1.5.0