Skip to content

Commit

Permalink
Multibyte String Enhancements: Add u modifier to preg_match()
Browse files Browse the repository at this point in the history
  • Loading branch information
raamdev committed Mar 4, 2016
1 parent 62de332 commit d41f2ea
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions src/includes/traits/Ac/ObUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,13 @@ public function maybeStartOutputBuffering()
if (!COMET_CACHE_FEEDS_ENABLE && $this->isFeed()) {
return $this->maybeSetDebugInfo($this::NC_DEBUG_FEED_REQUEST);
}
if (preg_match('/\/(?:wp\-[^\/]+|xmlrpc)\.php(?:[?]|$)/i', $_SERVER['REQUEST_URI'])) {
if (preg_match('/\/(?:wp\-[^\/]+|xmlrpc)\.php(?:[?]|$)/ui', $_SERVER['REQUEST_URI'])) {
return $this->maybeSetDebugInfo($this::NC_DEBUG_WP_SYSTEMATICS);
}
if (is_admin() || preg_match('/\/wp-admin(?:[\/?]|$)/i', $_SERVER['REQUEST_URI'])) {
if (is_admin() || preg_match('/\/wp-admin(?:[\/?]|$)/ui', $_SERVER['REQUEST_URI'])) {
return $this->maybeSetDebugInfo($this::NC_DEBUG_WP_ADMIN);
}
if (is_multisite() && preg_match('/\/files(?:[\/?]|$)/i', $_SERVER['REQUEST_URI'])) {
if (is_multisite() && preg_match('/\/files(?:[\/?]|$)/ui', $_SERVER['REQUEST_URI'])) {
return $this->maybeSetDebugInfo($this::NC_DEBUG_MS_FILES);
}
if ((!IS_PRO || !COMET_CACHE_WHEN_LOGGED_IN) && $this->isLikeUserLoggedIn()) {
Expand Down Expand Up @@ -277,7 +277,7 @@ public function outputBufferCallbackHandler($buffer, $phase)
if ((!IS_PRO || !COMET_CACHE_WHEN_LOGGED_IN) && $this->isLikeUserLoggedIn()) {
return (boolean) $this->maybeSetDebugInfo($this::NC_DEBUG_IS_LIKE_LOGGED_IN_USER);
}
if (!COMET_CACHE_CACHE_NONCE_VALUES && preg_match('/\b(?:_wpnonce|akismet_comment_nonce)\b/', $cache)) {
if (!COMET_CACHE_CACHE_NONCE_VALUES && preg_match('/\b(?:_wpnonce|akismet_comment_nonce)\b/u', $cache)) {
if (IS_PRO && COMET_CACHE_WHEN_LOGGED_IN && $this->isLikeUserLoggedIn()) {
if (!COMET_CACHE_CACHE_NONCE_VALUES_WHEN_LOGGED_IN) {
return (boolean) $this->maybeSetDebugInfo($this::NC_DEBUG_IS_LOGGED_IN_USER_NONCE);
Expand Down
8 changes: 4 additions & 4 deletions src/includes/traits/Plugin/InstallUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public function addWpCacheToWpConfig()
if (!($wp_config_file_contents_no_whitespace = php_strip_whitespace($wp_config_file))) {
return ''; // Failure; file empty
}
if (preg_match('/\bdefine\s*\(\s*([\'"])WP_CACHE\\1\s*,\s*(?:\-?[1-9][0-9\.]*|TRUE|([\'"])(?:[^0\'"]|[^\'"]{2,})\\2)\s*\)\s*;/i', $wp_config_file_contents_no_whitespace)) {
if (preg_match('/\bdefine\s*\(\s*([\'"])WP_CACHE\\1\s*,\s*(?:\-?[1-9][0-9\.]*|TRUE|([\'"])(?:[^0\'"]|[^\'"]{2,})\\2)\s*\)\s*;/ui', $wp_config_file_contents_no_whitespace)) {
return $wp_config_file_contents; // It's already in there; no need to modify this file.
}
if (!($wp_config_file_contents = $this->removeWpCacheFromWpConfig())) {
Expand Down Expand Up @@ -195,16 +195,16 @@ public function removeWpCacheFromWpConfig()
if (!($wp_config_file_contents_no_whitespace = php_strip_whitespace($wp_config_file))) {
return ''; // Failure; file empty
}
if (!preg_match('/([\'"])WP_CACHE\\1/i', $wp_config_file_contents_no_whitespace)) {
if (!preg_match('/([\'"])WP_CACHE\\1/ui', $wp_config_file_contents_no_whitespace)) {
return $wp_config_file_contents; // Already gone.
}
if (preg_match('/\bdefine\s*\(\s*([\'"])WP_CACHE\\1\s*,\s*(?:0|FALSE|NULL|([\'"])0?\\2)\s*\)\s*;/i', $wp_config_file_contents_no_whitespace) && !is_writable($wp_config_file)) {
if (preg_match('/\bdefine\s*\(\s*([\'"])WP_CACHE\\1\s*,\s*(?:0|FALSE|NULL|([\'"])0?\\2)\s*\)\s*;/ui', $wp_config_file_contents_no_whitespace) && !is_writable($wp_config_file)) {
return $wp_config_file_contents; // It's already disabled, and since we can't write to this file let's let this slide.
}
if (!($wp_config_file_contents = preg_replace('/\bdefine\s*\(\s*([\'"])WP_CACHE\\1\s*,\s*(?:\-?[0-9\.]+|TRUE|FALSE|NULL|([\'"])[^\'"]*\\2)\s*\)\s*;/i', '', $wp_config_file_contents))) {
return ''; // Failure; something went terribly wrong here.
}
if (preg_match('/([\'"])WP_CACHE\\1/i', $wp_config_file_contents)) {
if (preg_match('/([\'"])WP_CACHE\\1/ui', $wp_config_file_contents)) {
return ''; // Failure; perhaps the `/wp-config.php` file contains syntax we cannot remove safely.
}
if (defined('DISALLOW_FILE_MODS') && DISALLOW_FILE_MODS) {
Expand Down
8 changes: 4 additions & 4 deletions src/includes/traits/Shared/CacheDirUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,10 +458,10 @@ public function deleteAllFilesDirsIn($dir, $delete_dir_too = false)
$wp_content_dir = $this->nDirSeps(WP_CONTENT_DIR);
$wp_content_dir_regex = preg_quote($wp_content_dir, '/');

if (!preg_match('/^'.$wp_content_dir_regex.'\/[^\/]+/i', $dir)) {
if (!preg_match('/^'.$wp_content_dir_regex.'\/[^\/]+/ui', $dir)) {
return $counter; // Security flag; do nothing in this case.
}
if (preg_match('/^'.$wp_content_dir_regex.'\/(?:mu\-plugins|themes|plugins)(?:\/|$)/i', $dir)) {
if (preg_match('/^'.$wp_content_dir_regex.'\/(?:mu\-plugins|themes|plugins)(?:\/|$)/ui', $dir)) {
return $counter; // Security flag; do nothing in this case.
}
/* ------- Begin lock state... ----------- */
Expand Down Expand Up @@ -564,10 +564,10 @@ public function eraseAllFilesDirsIn($dir, $erase_dir_too = false)
$wp_content_dir = $this->nDirSeps(WP_CONTENT_DIR);
$wp_content_dir_regex = preg_quote($wp_content_dir, '/');

if (!preg_match('/^'.$wp_content_dir_regex.'\/[^\/]+/i', $dir)) {
if (!preg_match('/^'.$wp_content_dir_regex.'\/[^\/]+/ui', $dir)) {
return $counter; // Security flag; do nothing in this case.
}
if (preg_match('/^'.$wp_content_dir_regex.'\/(?:mu\-plugins|themes|plugins)(?:\/|$)/i', $dir)) {
if (preg_match('/^'.$wp_content_dir_regex.'\/(?:mu\-plugins|themes|plugins)(?:\/|$)/ui', $dir)) {
return $counter; // Security flag; do nothing in this case.
}
clearstatcache(); // Clear stat cache to be sure we have a fresh start below.
Expand Down
4 changes: 2 additions & 2 deletions src/includes/traits/Shared/ConditionalUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public function isLocalhost()
if (defined('LOCALHOST')) {
return $is = (boolean) LOCALHOST;
}
if (preg_match('/\b(?:localhost|127\.0\.0\.1)\b/i', $this->hostToken())) {
if (preg_match('/\b(?:localhost|127\.0\.0\.1)\b/ui', $this->hostToken())) {
return $is = true;
}
return $is = false;
Expand Down Expand Up @@ -323,7 +323,7 @@ public function hasACacheableStatus()
return $is = false; // A non-2xx & non-404 status code.
}
foreach ($this->headersList() as $_key => $_header) {
if (preg_match('/^(?:Retry\-After\:\s+(?P<retry>.+)|Status\:\s+(?P<status>[0-9]+)|HTTP\/[0-9]+(?:\.[0-9]+)?\s+(?P<http_status>[0-9]+))/i', $_header, $_m)) {
if (preg_match('/^(?:Retry\-After\:\s+(?P<retry>.+)|Status\:\s+(?P<status>[0-9]+)|HTTP\/[0-9]+(?:\.[0-9]+)?\s+(?P<http_status>[0-9]+))/ui', $_header, $_m)) {
if (!empty($_m['retry']) || (!empty($_m['status']) && $_m['status'][0] !== '2' && $_m['status'] !== '404')
|| (!empty($_m['http_status']) && $_m['http_status'][0] !== '2' && $_m['http_status'] !== '404')
) {
Expand Down
4 changes: 2 additions & 2 deletions src/includes/traits/Shared/FsUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public function nDirSeps($dir_file, $allow_trailing_slash = false)
return ''; // Catch empty string.
}
if (strpos($dir_file, '://' !== false)) {
if (preg_match('/^(?P<stream_wrapper>[a-zA-Z0-9]+)\:\/\//', $dir_file, $stream_wrapper)) {
if (preg_match('/^(?P<stream_wrapper>[a-zA-Z0-9]+)\:\/\//u', $dir_file, $stream_wrapper)) {
$dir_file = preg_replace('/^(?P<stream_wrapper>[a-zA-Z0-9]+)\:\/\//', '', $dir_file);
}
}
if (strpos($dir_file, ':' !== false)) {
if (preg_match('/^(?P<drive_letter>[a-zA-Z])\:[\/\\\\]/', $dir_file)) {
if (preg_match('/^(?P<drive_letter>[a-zA-Z])\:[\/\\\\]/u', $dir_file)) {
$dir_file = preg_replace_callback('/^(?P<drive_letter>[a-zA-Z])\:[\/\\\\]/', create_function('$m', 'return strtoupper($m[0]);'), $dir_file);
}
}
Expand Down

0 comments on commit d41f2ea

Please sign in to comment.