Fix instances of preg_quote() without second parameter
authorBartosz Dziewoński <matma.rex@gmail.com>
Thu, 25 Jun 2015 17:43:56 +0000 (19:43 +0200)
committerBartosz Dziewoński <matma.rex@gmail.com>
Thu, 25 Jun 2015 17:43:56 +0000 (19:43 +0200)
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
includes/parser/ParserOutput.php
includes/specials/SpecialAllMessages.php
tests/phpunit/includes/specials/SpecialSearchTest.php

index 6a699f9..d27d2c6 100644 (file)
@@ -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
                );
index a8db1c9..7068bd7 100644 (file)
@@ -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
                        );
index f3e896a..41c2f93 100644 (file)
@@ -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;
index 83489c6..5482b97 100644 (file)
@@ -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 <title>"
                );