Skip to content

Commit

Permalink
[ticket/9747] Improve word censor.
Browse files Browse the repository at this point in the history
Better handling of the asterisk inside censor pattern like 'bad*word' etc.

PHPBB3-9747
  • Loading branch information
rxu committed Jul 25, 2010
1 parent fc25fe6 commit 4d0a53b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion phpBB/includes/cache.php
Expand Up @@ -88,7 +88,14 @@ function obtain_word_list()
{
if ($unicode)
{
$censors['match'][] = '#(?<![\p{Nd}\p{L}_])(' . str_replace('\*', '[\p{Nd}\p{L}_]*?', preg_quote($row['word'], '#')) . ')(?![\p{Nd}\p{L}_])#iu';
// Unescape the asterisk to simplify further conversions
$row['word'] = str_replace('\*', '*', preg_quote($row['word'], '#'));

// Replace the asterisk inside the pattern, at the start and at the end of it with regexes
$row['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}_-]*?'), $row['word']);

// Generate the final substitution
$censors['match'][] = '#(?<![\p{Nd}\p{L}_-])(' . $row['word'] . ')(?![\p{Nd}\p{L}_-])#iu';
}
else
{
Expand Down

0 comments on commit 4d0a53b

Please sign in to comment.