Fixed a bug affecting some locales where word censoring would not work on words beginning or ending with an accented character.
diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php
index 6e61f77..e79a241 100644
--- a/system/helpers/text_helper.php
+++ b/system/helpers/text_helper.php
@@ -230,21 +230,28 @@
{
return $str;
}
+
+ $str = ' '.$str.' ';
- $str = ' '.$str.' ';
+ // \w, \b and a few others do not match on a unicode character
+ // set for performance reasons. As a result words like über
+ // will not match on a word boundary. Instead, we'll assume that
+ // a bad word will be bookeneded by any of these characters.
+ $delim = '[-_\'\"`(){}<>\[\]|!?@#%&,.:;^~*+=\/ 0-9\n\r\t]';
+
foreach ($censored as $badword)
{
if ($replacement != '')
{
- $str = preg_replace("/\b(".str_replace('\*', '\w*?', preg_quote($badword, '/')).")\b/i", $replacement, $str);
+ $str = preg_replace("/({$delim})(".str_replace('\*', '\w*?', preg_quote($badword, '/')).")({$delim})/i", "\\1{$replacement}\\3", $str);
}
else
{
- $str = preg_replace("/\b(".str_replace('\*', '\w*?', preg_quote($badword, '/')).")\b/ie", "str_repeat('#', strlen('\\1'))", $str);
+ $str = preg_replace("/({$delim})(".str_replace('\*', '\w*?', preg_quote($badword, '/')).")({$delim})/ie", "'\\1'.str_repeat('#', strlen('\\2')).'\\3'", $str);
}
}
-
- return trim($str);
+
+ return trim($str);
}
}
diff --git a/user_guide/changelog.html b/user_guide/changelog.html
index dbe4c66..5015296 100644
--- a/user_guide/changelog.html
+++ b/user_guide/changelog.html
@@ -106,6 +106,7 @@
<li>Fixed a bug with non-breaking space cleanup in Typography::auto_typography().</li>
<li>Fixed a bug in database escaping where a compound statement (ie: SUM()) wasn't handled correctly with database prefixes.</li>
<li>Fixed a bug when an opening quote is preceded by a paragraph tag and immediately followed by another tag.</li>
+ <li>Fixed a bug in the Text Helper affecting some locales where word_censor() would not work on words beginning or ending with an accented character.</li>
<li>Tweaked Typography::auto_typography() for some edge-cases.</li>
</ul>