note 107411 deleted from function.addslashes by tularis
| From: | tularis@php.net | Date: | Wed, 08 Feb 2012 17:26:46 +0000 |
| Subject: | note 107411 deleted from function.addslashes by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-185918@lists.php.net to get a copy of this message | ||
Note Submitter: mike at eastghost dot com
----
Is this function safe for UTF-8 ?
Note that this function (addslashes()) gets called by preg_replace() function when using the
"/e" modifier - so if you're using preg_replace() on UTF-8 data, but then
preg_replace() is calling a function that's not UTF-8 safe (i.e., this function, addslashes() )
then all sorts of weirdness can happen...
Here's an example:
// goal: change the "[post=<> /]" present in $utf_data into a hyperlink: "<a
href="site/post/id">Post Title</a>"
$utf_data = 'some forum text in UTF8 format and a reference to a [post=4aa44b39dbeff00000b0
/]';
$html_ours[0] = '@\[p(?:ost){0,1}=(.{1,24})\ {0,}\/\]@Uieu';
$html_oursr[0] = 'debdcode_post( $1 )';
function debdcode_post( $in )
{
// lookup the $in from database
// return string
return '<a href="/post/'. $in. '">Post Title</a>';
}
$out = preg_replace( $html_ours, $html_oursr, $utf_data );
Whenever the string "=4a" (or any string of general pattern "=" then integer
then at least one letter) is passed, preg_replace() bombs with an odd error, APPARENTLY because the
addslashes() chokes on UTF-8.
See bug report # 61001
Workaround appears to be using
preg_replace_callback()
instead of an array'd stack of pattern/replacements passed to preg_replace()