mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 14:18:52 +00:00
[ticket/9933] Adjust word censor regex for non-unicode mode.
PHPBB3-9933
This commit is contained in:
parent
1359cf6547
commit
8c1866bc0c
1 changed files with 8 additions and 4 deletions
|
@ -3451,11 +3451,11 @@ function get_censor_preg_expression($word)
|
||||||
$unicode = ((version_compare(PHP_VERSION, '5.1.0', '>=') || (version_compare(PHP_VERSION, '5.0.0-dev', '<=') && version_compare(PHP_VERSION, '4.4.0', '>='))) && @preg_match('/\p{L}/u', 'a') !== false) ? true : false;
|
$unicode = ((version_compare(PHP_VERSION, '5.1.0', '>=') || (version_compare(PHP_VERSION, '5.0.0-dev', '<=') && version_compare(PHP_VERSION, '4.4.0', '>='))) && @preg_match('/\p{L}/u', 'a') !== false) ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Unescape the asterisk to simplify further conversions
|
||||||
|
$word = str_replace('\*', '*', preg_quote($word, '#'));
|
||||||
|
|
||||||
if ($unicode)
|
if ($unicode)
|
||||||
{
|
{
|
||||||
// Unescape the asterisk to simplify further conversions
|
|
||||||
$word = str_replace('\*', '*', preg_quote($word, '#'));
|
|
||||||
|
|
||||||
// Replace asterisk(s) inside the pattern, at the start and at the end of it with regexes
|
// Replace asterisk(s) inside the pattern, at the start and at the end of it with regexes
|
||||||
$word = preg_replace(array('#(?<=[\p{Nd}\p{L}_])\*+(?=[\p{Nd}\p{L}_])#iu', '#^\*+#', '#\*+$#'), array('([\x20]*?|[\p{Nd}\p{L}_-]*?)', '[\p{Nd}\p{L}_-]*?', '[\p{Nd}\p{L}_-]*?'), $word);
|
$word = preg_replace(array('#(?<=[\p{Nd}\p{L}_])\*+(?=[\p{Nd}\p{L}_])#iu', '#^\*+#', '#\*+$#'), array('([\x20]*?|[\p{Nd}\p{L}_-]*?)', '[\p{Nd}\p{L}_-]*?', '[\p{Nd}\p{L}_-]*?'), $word);
|
||||||
|
|
||||||
|
@ -3464,7 +3464,11 @@ function get_censor_preg_expression($word)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$preg_expr = '#(?<!\S)(' . str_replace('\*', '\S*?', preg_quote($word, '#')) . ')(?!\S)#iu';
|
// Replace the asterisk inside the pattern, at the start and at the end of it with regexes
|
||||||
|
$word = preg_replace(array('#(?<=\S)\*+(?=\S)#iu', '#^\*+#', '#\*+$#'), array('(\x20*?\S*?)', '\S*?', '\S*?'), $word);
|
||||||
|
|
||||||
|
// Generate the final substitution
|
||||||
|
$preg_expr = '#(?<!\S)(' . $word . ')(?!\S)#iu';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $preg_expr;
|
return $preg_expr;
|
||||||
|
|
Loading…
Add table
Reference in a new issue