Update of /cvsroot/phplib/php-lib-stable/php
In directory usw-pr-cvs1:/tmp/cvs-serv2803
Modified Files:
template.inc
Log Message:
more elegant fix to the problem of subst stripping '$n', '\n' and '\\' strings
Index: template.inc
===================================================================
RCS file: /cvsroot/phplib/php-lib-stable/php/template.inc,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** template.inc 25 Apr 2002 11:56:40 -0000 1.10
--- template.inc 25 Apr 2002 12:49:17 -0000 1.11
***************
*** 31,37 ****
* in finish, the replacement string referenced an unset variable (rha)
* loadfile would try to load a file if the varval had been set to "" (rha)
- * '$n' in variable values was being stripped by subst in PHP 4.0.4+ (John Mandeville)
- * '\n' was also being stripped. Fix by replacing with &#(36|92); in set_var and unreplacing in finish (rha)
* in get_undefined, only match non-whitespace in variable tags as in finish. (Layne Weathers & rha)
*
*/
--- 31,36 ----
* in finish, the replacement string referenced an unset variable (rha)
* loadfile would try to load a file if the varval had been set to "" (rha)
* in get_undefined, only match non-whitespace in variable tags as in finish. (Layne Weathers & rha)
+ * more elegant fix to the problem of subst stripping '$n', '\n' and '\\' strings (rha)
*
*/
***************
*** 166,170 ****
if (!empty($varname)) {
if ($this->debug) print "scalar: set *$varname* to *$value*<br>\n";
- $value = preg_replace(array('/\$([0-9])/', '/\\\\([0-9])/'), array('$\1', '\\1'), $value);
$this->varkeys[$varname] = "/".$this->varname($varname)."/";
$this->varvals[$varname] = $value;
--- 165,168 ----
***************
*** 175,179 ****
if (!empty($k)) {
if ($this->debug) print "array: set *$k* to *$v*<br>\n";
- $v = preg_replace(array('/\$([0-9])/', '/\\\\([0-9])/'), array('$\1', '\\1'), $v);
$this->varkeys[$k] = "/".$this->varname($k)."/";
$this->varvals[$k] = $v;
--- 173,176 ----
***************
*** 189,192 ****
--- 186,190 ----
*/
function subst($varname) {
+ $varvals_quoted = array();
if (!$this->loadfile($varname)) {
$this->halt("subst: unable to load $varname.");
***************
*** 194,199 ****
}
$str = $this->get_var($varname);
! $str = preg_replace($this->varkeys, $this->varvals, $str);
return $str;
}
--- 192,203 ----
}
+ // quote the replacement strings to prevent bogus stripping of special chars
+ reset($this->varvals);
+ while(list($k, $v) = each($this->varvals)) {
+ $varvals_quoted[$k] = preg_replace(array('/\\\\/', '/\$/'), array('\\\\\\\\', '\\\\$'), $v);
+ }
+
$str = $this->get_var($varname);
! $str = preg_replace($this->varkeys, $varvals_quoted, $str);
return $str;
}
***************
*** 337,341 ****
}
- $str = preg_replace(array('/$([0-9])/', '/\([0-9])/'), array('$\1', '\\\1'), $str);
return $str;
}
--- 341,344 ----
|