Pass delimiter to preg_quote
authorUmherirrender <umherirrender_de.wp@web.de>
Sat, 1 Sep 2018 12:39:56 +0000 (14:39 +0200)
committerUmherirrender <umherirrender_de.wp@web.de>
Sat, 1 Sep 2018 12:52:16 +0000 (14:52 +0200)
This ensure that the regex is escaped correctly,
even when the quoted value never contains the delimiter

Change-Id: I2dc93fa0154d4506c276a30cab008bc2ac5e0687

includes/LinkFilter.php
includes/libs/rdbms/database/DatabaseSqlite.php
tests/phpunit/MediaWikiTestCase.php
tests/phpunit/structure/ApiStructureTest.php

index 17b4d56..3b03f87 100644 (file)
@@ -65,7 +65,7 @@ class LinkFilter {
         * @return string Regex pattern, for preg_match()
         */
        private static function makeRegex( $filterEntry, $protocol ) {
-               $regex = '!' . preg_quote( $protocol );
+               $regex = '!' . preg_quote( $protocol, '!' );
                if ( substr( $filterEntry, 0, 2 ) == '*.' ) {
                        $regex .= '(?:[A-Za-z0-9.-]+\.|)';
                        $filterEntry = substr( $filterEntry, 2 );
index 1b9675a..c8edc39 100644 (file)
@@ -974,7 +974,9 @@ class DatabaseSqlite extends Database {
                }
                $sql = $obj->sql;
                $sql = preg_replace(
-                       '/(?<=\W)"?' . preg_quote( trim( $this->addIdentifierQuotes( $oldName ), '"' ) ) . '"?(?=\W)/',
+                       '/(?<=\W)"?' .
+                               preg_quote( trim( $this->addIdentifierQuotes( $oldName ), '"' ), '/' ) .
+                               '"?(?=\W)/',
                        $this->addIdentifierQuotes( $newName ),
                        $sql,
                        1
index 5cc45f5..aaf9f14 100644 (file)
@@ -1705,7 +1705,7 @@ abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase {
 
                $originalTables = $db->listTables( $db->_originalTablePrefix, __METHOD__ );
                if ( $prefix === 'unprefixed' ) {
-                       $originalPrefixRegex = '/^' . preg_quote( $db->_originalTablePrefix ) . '/';
+                       $originalPrefixRegex = '/^' . preg_quote( $db->_originalTablePrefix, '/' ) . '/';
                        $originalTables = array_map(
                                function ( $pt ) use ( $originalPrefixRegex ) {
                                        return preg_replace( $originalPrefixRegex, '', $pt );
index 692bd73..95d3b60 100644 (file)
@@ -454,7 +454,12 @@ class ApiStructureTest extends MediaWikiTestCase {
                                        }
 
                                        $keys = implode( '|',
-                                               array_map( 'preg_quote', array_keys( $config[ApiBase::PARAM_TEMPLATE_VARS] ) )
+                                               array_map(
+                                                       function ( $key ) {
+                                                               return preg_quote( $key, '/' );
+                                                       },
+                                                       array_keys( $config[ApiBase::PARAM_TEMPLATE_VARS] )
+                                               )
                                        );
                                        $this->assertRegExp( '/^(?>[^{}]+|\{(?:' . $keys . ')\})+$/', $param,
                                                "$param: Name may not contain '{' or '}' other than as defined by PARAM_TEMPLATE_VARS" );