Update of /cvsroot/phplib/php-lib/php/ext
In directory usw-pr-cvs1:/tmp/cvs-serv4500a
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/php/ext/template.inc,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** template.inc 25 Apr 2002 11:59:46 -0000 1.7
--- template.inc 25 Apr 2002 12:53:38 -0000 1.8
***************
*** 30,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)
- * '$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)
*
*
--- 30,35 ----
* 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)
*
*
***************
*** 352,356 ****
printf("<b>set_var:</b> (with scalar) <b>%s</b> = '%s'<br>\n", $varname, htmlentities($value));
}
- $value = preg_replace(array('/\$([0-9])/', '/\\\\([0-9])/'), array('$\1', '\\1'), $value);
$this->varkeys[$varname] = "/".$this->varname($varname)."/";
if ($append && isset($this->varvals[$varname])) {
--- 351,354 ----
***************
*** 367,371 ****
printf("<b>set_var:</b> (with array) <b>%s</b> = '%s'<br>\n", $k, htmlentities($v));
}
- $v = preg_replace(array('/\$([0-9])/', '/\\\\([0-9])/'), array('$\1', '\\1'), $v);
$this->varkeys[$k] = "/".$this->varname($k)."/";
if ($append && isset($this->varvals[$k])) {
--- 365,368 ----
***************
*** 396,399 ****
--- 393,397 ----
*/
function subst($varname) {
+ $varvals_quoted = array();
if ($this->debug & 4) {
echo "<p><b>subst:</b> varname = $varname</p>\n";
***************
*** 404,409 ****
}
$str = $this->get_var($varname);
! $str = preg_replace($this->varkeys, $this->varvals, $str);
return $str;
}
--- 402,413 ----
}
+ // 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;
}
***************
*** 678,682 ****
}
- $str = preg_replace(array('/$([0-9])/', '/\([0-9])/'), array('$\1', '\\\1'), $str);
return $str;
}
--- 682,685 ----
|