From 1021f201007bfe8ba9789115ef8e0e48abc0adfd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bartosz=20Dziewo=C5=84ski?= Date: Thu, 25 Jun 2015 19:43:56 +0200 Subject: [PATCH] Fix instances of preg_quote() without second parameter This might work in specific cases, depending on the string we're quoting, but is never correct. The instance in SpecialAllMessages.php was resulting in incorrect behavior (and log spam, T103879). Searched for this regex: preg_quote\((?:\([^)]+?\)|[^,()])+?\) Change-Id: Icc88775970f4927ddf953e5ad7c5c19d59491573 --- includes/filebackend/FileBackendMultiWrite.php | 2 +- includes/parser/ParserOutput.php | 2 +- includes/specials/SpecialAllMessages.php | 2 +- tests/phpunit/includes/specials/SpecialSearchTest.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/filebackend/FileBackendMultiWrite.php b/includes/filebackend/FileBackendMultiWrite.php index 6a699f9410..d27d2c6850 100644 --- a/includes/filebackend/FileBackendMultiWrite.php +++ b/includes/filebackend/FileBackendMultiWrite.php @@ -433,7 +433,7 @@ class FileBackendMultiWrite extends FileBackend { */ protected function substPaths( $paths, FileBackendStore $backend ) { return preg_replace( - '!^mwstore://' . preg_quote( $this->name ) . '/!', + '!^mwstore://' . preg_quote( $this->name, '!' ) . '/!', StringUtils::escapeRegexReplacement( "mwstore://{$backend->getName()}/" ), $paths // string or array ); diff --git a/includes/parser/ParserOutput.php b/includes/parser/ParserOutput.php index a8db1c9521..7068bd717e 100644 --- a/includes/parser/ParserOutput.php +++ b/includes/parser/ParserOutput.php @@ -103,7 +103,7 @@ class ParserOutput extends CacheTime { $text = str_replace( array( Parser::TOC_START, Parser::TOC_END ), '', $text ); } else { $text = preg_replace( - '#' . preg_quote( Parser::TOC_START ) . '.*?' . preg_quote( Parser::TOC_END ) . '#s', + '#' . preg_quote( Parser::TOC_START, '#' ) . '.*?' . preg_quote( Parser::TOC_END, '#' ) . '#s', '', $text ); diff --git a/includes/specials/SpecialAllMessages.php b/includes/specials/SpecialAllMessages.php index f3e896a936..41c2f93377 100644 --- a/includes/specials/SpecialAllMessages.php +++ b/includes/specials/SpecialAllMessages.php @@ -130,7 +130,7 @@ class AllMessagesTablePager extends TablePager { if ( $prefix !== null ) { $this->displayPrefix = $prefix->getDBkey(); - $this->prefix = '/^' . preg_quote( $this->displayPrefix ) . '/i'; + $this->prefix = '/^' . preg_quote( $this->displayPrefix, '/' ) . '/i'; } else { $this->displayPrefix = false; $this->prefix = false; diff --git a/tests/phpunit/includes/specials/SpecialSearchTest.php b/tests/phpunit/includes/specials/SpecialSearchTest.php index 83489c65b7..5482b9753d 100644 --- a/tests/phpunit/includes/specials/SpecialSearchTest.php +++ b/tests/phpunit/includes/specials/SpecialSearchTest.php @@ -136,7 +136,7 @@ class SpecialSearchTest extends MediaWikiTestCase { # Compare :-] $this->assertRegExp( - '/' . preg_quote( $term ) . '/', + '/' . preg_quote( $term, '/' ) . '/', $pageTitle, "Search term '{$term}' should not be expanded in Special:Search " ); -- 2.20.1