|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
robocoder Smarty n00b
Joined: 17 Jan 2009 Posts: 2
|
Posted: Thu Dec 31, 2009 7:06 pm Post subject: 2.x/3: outputfilter.trimwhitespace mbstring.func_overload |
|
|
The problem here is that there's no multibyte-aware version of substr_replace(). Here's a patch against 2.6.26. (Note it also affects Smarty 3.)
Code: |
Index: outputfilter.trimwhitespace.php
===================================================================
--- outputfilter.trimwhitespace.php (revision 1735)
+++ outputfilter.trimwhitespace.php (working copy)
@@ -62,6 +62,15 @@
}
function smarty_outputfilter_trimwhitespace_replace($search_str, $replace, &$subject) {
+ // If mbstring overloads substr and strlen functions, we have to
+ // override it's internal encoding
+ if (function_exists('mb_internal_encoding') &&
+ ((int) ini_get('mbstring.func_overload')) & 2) {
+
+ $mbIntEnc = mb_internal_encoding();
+ mb_internal_encoding('ASCII');
+ }
+
$_len = strlen($search_str);
$_pos = 0;
for ($_i=0, $_count=count($replace); $_i<$_count; $_i++)
@@ -70,6 +79,9 @@
else
break;
+ if (isset($mbIntEnc)) {
+ mb_internal_encoding($mbIntEnc);
+ }
}
?>
|
|
|
Back to top |
|
stayclose Smarty Rookie
Joined: 16 Feb 2010 Posts: 9
|
Posted: Wed Jul 21, 2010 2:27 pm Post subject: Re: 2.x/3: outputfilter.trimwhitespace mbstring.func_overloa |
|
|
This bug is still there, even in Smarty3 RC3.
In some cases the @@@SMARTY:TRIM:SCRIPT@@@ doesn't get completly replaced by $replace[$_i] and leaves something like:
</script>@
I have tried the below patch and it seems to work. I am also using the overload method. I am not sure about what the affect may be by switching the internal encoding from UTF-8 to ASCII and back again.
Since preg_replace is used in smarty_outputfilter_trimwhitespace smarty_outputfilter_trimwhitespace_replace could be done like this:
function smarty_outputfilter_trimwhitespace_replace($search_str, $replace, &$subject) {
$_replace_total = count($replace);
$_len = strlen($search_str);
$_pos = 0;
for ($_i = 0; $_i < $_replace_total; $_i++) {
$subject = preg_replace("!$search_str!", $replace[$_i], $subject, 1);
}
}
I haven't tested it thoroughly but it looks good.
robocoder wrote: | The problem here is that there's no multibyte-aware version of substr_replace(). Here's a patch against 2.6.26. (Note it also affects Smarty 3.)
Code: |
Index: outputfilter.trimwhitespace.php
===================================================================
--- outputfilter.trimwhitespace.php (revision 1735)
+++ outputfilter.trimwhitespace.php (working copy)
@@ -62,6 +62,15 @@
}
function smarty_outputfilter_trimwhitespace_replace($search_str, $replace, &$subject) {
+ // If mbstring overloads substr and strlen functions, we have to
+ // override it's internal encoding
+ if (function_exists('mb_internal_encoding') &&
+ ((int) ini_get('mbstring.func_overload')) & 2) {
+
+ $mbIntEnc = mb_internal_encoding();
+ mb_internal_encoding('ASCII');
+ }
+
$_len = strlen($search_str);
$_pos = 0;
for ($_i=0, $_count=count($replace); $_i<$_count; $_i++)
@@ -70,6 +79,9 @@
else
break;
+ if (isset($mbIntEnc)) {
+ mb_internal_encoding($mbIntEnc);
+ }
}
?>
|
|
|
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|