From d41f2ea41af5793b18a6fcd787101e1bff20fc9f Mon Sep 17 00:00:00 2001 From: Raam Dev Date: Thu, 3 Mar 2016 20:24:38 -0500 Subject: [PATCH] Multibyte String Enhancements: Add `u` modifier to `preg_match()` See websharks/comet-cache#703 --- src/includes/traits/Ac/ObUtils.php | 8 ++++---- src/includes/traits/Plugin/InstallUtils.php | 8 ++++---- src/includes/traits/Shared/CacheDirUtils.php | 8 ++++---- src/includes/traits/Shared/ConditionalUtils.php | 4 ++-- src/includes/traits/Shared/FsUtils.php | 4 ++-- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/includes/traits/Ac/ObUtils.php b/src/includes/traits/Ac/ObUtils.php index 042bf077..e9d974da 100644 --- a/src/includes/traits/Ac/ObUtils.php +++ b/src/includes/traits/Ac/ObUtils.php @@ -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()) { @@ -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); diff --git a/src/includes/traits/Plugin/InstallUtils.php b/src/includes/traits/Plugin/InstallUtils.php index c999fd25..f1fe4bf2 100644 --- a/src/includes/traits/Plugin/InstallUtils.php +++ b/src/includes/traits/Plugin/InstallUtils.php @@ -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())) { @@ -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) { diff --git a/src/includes/traits/Shared/CacheDirUtils.php b/src/includes/traits/Shared/CacheDirUtils.php index 8adf4c8b..2a71abf3 100644 --- a/src/includes/traits/Shared/CacheDirUtils.php +++ b/src/includes/traits/Shared/CacheDirUtils.php @@ -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... ----------- */ @@ -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. diff --git a/src/includes/traits/Shared/ConditionalUtils.php b/src/includes/traits/Shared/ConditionalUtils.php index 3f20c393..5c317be2 100644 --- a/src/includes/traits/Shared/ConditionalUtils.php +++ b/src/includes/traits/Shared/ConditionalUtils.php @@ -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; @@ -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.+)|Status\:\s+(?P[0-9]+)|HTTP\/[0-9]+(?:\.[0-9]+)?\s+(?P[0-9]+))/i', $_header, $_m)) { + if (preg_match('/^(?:Retry\-After\:\s+(?P.+)|Status\:\s+(?P[0-9]+)|HTTP\/[0-9]+(?:\.[0-9]+)?\s+(?P[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') ) { diff --git a/src/includes/traits/Shared/FsUtils.php b/src/includes/traits/Shared/FsUtils.php index e8ccf641..5a2048f0 100644 --- a/src/includes/traits/Shared/FsUtils.php +++ b/src/includes/traits/Shared/FsUtils.php @@ -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[a-zA-Z0-9]+)\:\/\//', $dir_file, $stream_wrapper)) { + if (preg_match('/^(?P[a-zA-Z0-9]+)\:\/\//u', $dir_file, $stream_wrapper)) { $dir_file = preg_replace('/^(?P[a-zA-Z0-9]+)\:\/\//', '', $dir_file); } } if (strpos($dir_file, ':' !== false)) { - if (preg_match('/^(?P[a-zA-Z])\:[\/\\\\]/', $dir_file)) { + if (preg_match('/^(?P[a-zA-Z])\:[\/\\\\]/u', $dir_file)) { $dir_file = preg_replace_callback('/^(?P[a-zA-Z])\:[\/\\\\]/', create_function('$m', 'return strtoupper($m[0]);'), $dir_file); } }