aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/functions.php
diff options
context:
space:
mode:
authorAndreas Fischer <bantu@phpbb.com>2011-01-16 20:03:08 +0100
committerAndreas Fischer <bantu@phpbb.com>2011-01-16 20:13:05 +0100
commit97be6e794647d0853274c5d8e68a9fbe727dba51 (patch)
treec767c332a8226ce2b8e9166fd9935cc06b86669b /phpBB/includes/functions.php
parent8c1866bc0c1ac4a3b58edfaf3f3914361deb1fab (diff)
downloadforums-97be6e794647d0853274c5d8e68a9fbe727dba51.tar
forums-97be6e794647d0853274c5d8e68a9fbe727dba51.tar.gz
forums-97be6e794647d0853274c5d8e68a9fbe727dba51.tar.bz2
forums-97be6e794647d0853274c5d8e68a9fbe727dba51.tar.xz
forums-97be6e794647d0853274c5d8e68a9fbe727dba51.zip
[ticket/9933] Add $use_unicode parameter to get_censor_preg_expression().
Rename $unicode to $unicode_support, pass in $use_unicode defaulting to true. In unit tests we can now pass in $use_unicode as false and also test the code path that is taken when PCRE does not support unicode. PHPBB3-9933
Diffstat (limited to 'phpBB/includes/functions.php')
-rw-r--r--phpBB/includes/functions.php13
1 files changed, 7 insertions, 6 deletions
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index 20d9d4e0f5..1bcbfd2a83 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -3432,13 +3432,14 @@ function get_preg_expression($mode)
* Generate regexp for naughty words censoring
* Depends on whether installed PHP version supports unicode properties
*
-* @param string $word word template to be replaced
+* @param string $word word template to be replaced
+* @param bool $use_unicode whether or not to take advantage of PCRE supporting unicode
*
* @return string $preg_expr regex to use with word censor
*/
-function get_censor_preg_expression($word)
+function get_censor_preg_expression($word, $use_unicode = true)
{
- static $unicode = null;
+ static $unicode_support = null;
if (empty($word))
{
@@ -3446,15 +3447,15 @@ function get_censor_preg_expression($word)
}
// Check whether PHP version supports unicode properties
- if (is_null($unicode))
+ if (is_null($unicode_support))
{
- $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_support = ((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 ($use_unicode && $unicode_support)
{
// 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);