Re: [SMARTY] bug? security hole? undocumented magic in php?
| From: | Greg Stark | Date: | Sat, 26 Apr 2003 05:37:27 +0000 |
| Subject: | Re: [SMARTY] bug? security hole? undocumented magic in php? | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-9388@lists.php.net to get a copy of this message | ||
"Rob Schultz" <schultzr@kattare.com> writes:
> > It's still a bug that it uses "\\1 \\2 \\3" I think it's
> > supposed to be
> > "\$1 \$2 \$3".
> in php it is \1 or \\1 if you need to escape it. as you can read here
> http://www.php.net/manual/en/pcre.pattern.syntax.php
Thank you for the reference, this page is much more verbose than the
documentation I was using.
However it doesn't back up your assertion that \1 vs $1 is at all related to
the addition of backslashes. In fact the page you pointed me at simply says
point blank that $1 is preferred over \1.
There are some user contributed explanations of my issue there however. Mostly
they suggest using str_replace to get rid of the excess backslashes. (On the
other hand one person says to use stripslashes which is wrong, and another
said to use prereg_quote! I guess you get what you pay for with free help.)
For example guidod at gmx dot de says:
> always remember that the capture-texts $1..$n are run through addslashes()
> for the /e-case, converting \,'," into \\,\',\". The /e-val will handle
> quotations however reducing just two of the three backslashes back for
> quoted $1..$n-arguments
>
> "my_func(\"$1\")" reduces \\ and \" but not \'
> "my_func('$1')" reduces \\ and \' but not \"
>
> Therefore the remaining escaped quotationmark is seen by the function and a
> str_replace '\"','"', must be used there to get at the original
> captured
> text.
However other posters also pointed out other problems with embedded newlines
and with numeric text following the escapes. I think they're also both
solvable, but it defeats the purpose of using a simple elegant prereg_replace
over an explicit loop if it requires extra code with obscure motivation to
work-around the api.
I've settled on copying Smarty's logic of doing a prereg_matchall and a
prereg_split and the manually interleaving the content back together. It works
pretty well now. And while it's way less efficient since it's in a prefilter
so it shouldn't run often enough to be a problem.
It just makes me sad to have 11 lines of opaque code for what should be a
simple one-liner.
--
greg