summaryrefslogtreecommitdiffstats
path: root/system/helpers/text_helper.php
diff options
context:
space:
mode:
authorDerek Jones <derek.jones@ellislab.com>2009-01-21 18:52:13 +0100
committerDerek Jones <derek.jones@ellislab.com>2009-01-21 18:52:13 +0100
commitf1b721a3559e8eb95bc580a3f79c5c2e896c9932 (patch)
tree4dc3d972d42b716f946c82e80f2e2a3104a18d6e /system/helpers/text_helper.php
parent6ec22f5ca04a17035c2e9773e20702da905c340a (diff)
Fixed a bug affecting some locales where word censoring would not work on words beginning or ending with an accented character.
Diffstat (limited to 'system/helpers/text_helper.php')
-rw-r--r--system/helpers/text_helper.php17
1 files changed, 12 insertions, 5 deletions
diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php
index 6e61f776a..e79a2419d 100644
--- a/system/helpers/text_helper.php
+++ b/system/helpers/text_helper.php
@@ -230,21 +230,28 @@ if ( ! function_exists('word_censor'))
{
return $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]';
- $str = ' '.$str.' ';
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);
}
}