jenkins-bot has submitted this change and it was merged.

Change subject: Make a single colon an invalid title in php and js
......................................................................


Make a single colon an invalid title in php and js

When secureAndSplit gets a single colon as input, the leading colon
is stripped and produces a title with a empty string. This change makes
that impossible by moving the empty string check to after the substring
removal of the colon.

Bug: 54044
Change-Id: I574168c9ed281c535901c36dea7c179a4e794d20
---
M includes/Title.php
M resources/mediawiki/mediawiki.Title.js
M tests/phpunit/includes/TitleTest.php
M tests/qunit/suites/resources/mediawiki/mediawiki.Title.test.js
4 files changed, 12 insertions(+), 10 deletions(-)

Approvals:
  Krinkle: Looks good to me, but someone else must approve
  Parent5446: Looks good to me, approved
  Bartosz Dziewoński: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/includes/Title.php b/includes/Title.php
index 820842f..a949ac3 100644
--- a/includes/Title.php
+++ b/includes/Title.php
@@ -3163,10 +3163,6 @@
                $dbkey = preg_replace( '/[ 
_\xA0\x{1680}\x{180E}\x{2000}-\x{200A}\x{2028}\x{2029}\x{202F}\x{205F}\x{3000}]+/u',
 '_', $dbkey );
                $dbkey = trim( $dbkey, '_' );
 
-               if ( $dbkey == '' ) {
-                       return false;
-               }
-
                if ( strpos( $dbkey, UTF8_REPLACEMENT ) !== false ) {
                        # Contained illegal UTF-8 sequences or forbidden 
Unicode chars.
                        return false;
@@ -3176,12 +3172,16 @@
 
                # Initial colon indicates main namespace rather than specified 
default
                # but should not create invalid {ns,title} pairs such as 
{0,Project:Foo}
-               if ( ':' == $dbkey[0] ) {
+               if ( $dbkey !== '' && ':' == $dbkey[0] ) {
                        $this->mNamespace = NS_MAIN;
                        $dbkey = substr( $dbkey, 1 ); # remove the colon but 
continue processing
                        $dbkey = trim( $dbkey, '_' ); # remove any subsequent 
whitespace
                }
 
+               if ( $dbkey == '' ) {
+                       return false;
+               }
+
                # Namespace or interwiki prefix
                $firstPass = true;
                $prefixRegexp = "/^(.+?)_*:_*(.*)$/S";
diff --git a/resources/mediawiki/mediawiki.Title.js 
b/resources/mediawiki/mediawiki.Title.js
index de2d013..51770fd 100644
--- a/resources/mediawiki/mediawiki.Title.js
+++ b/resources/mediawiki/mediawiki.Title.js
@@ -126,12 +126,8 @@
                        // Trim underscores
                        .replace( rUnderscoreTrim, '' );
 
-               if ( title === '' ) {
-                       return false;
-               }
-
                // Process initial colon
-               if ( title.charAt( 0 ) === ':' ) {
+               if ( title !== '' && title.charAt( 0 ) === ':' ) {
                        // Initial colon means main namespace instead of 
specified default
                        namespace = NS_MAIN;
                        title = title
@@ -141,6 +137,10 @@
                                .replace( rUnderscoreTrim, '' );
                }
 
+               if ( title === '' ) {
+                       return false;
+               }
+
                // Process namespace prefix (if any)
                m = title.match( rSplit );
                if ( m ) {
diff --git a/tests/phpunit/includes/TitleTest.php 
b/tests/phpunit/includes/TitleTest.php
index 6bfe545..58f0146 100644
--- a/tests/phpunit/includes/TitleTest.php
+++ b/tests/phpunit/includes/TitleTest.php
@@ -66,6 +66,7 @@
                // Invalid
                foreach ( array(
                        '',
+                       ':',
                        '__  __',
                        '  __  ',
                        // Bad characters forbidden regardless of 
wgLegalTitleChars
diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.Title.test.js 
b/tests/qunit/suites/resources/mediawiki/mediawiki.Title.test.js
index cb0bf69..4083564 100644
--- a/tests/qunit/suites/resources/mediawiki/mediawiki.Title.test.js
+++ b/tests/qunit/suites/resources/mediawiki/mediawiki.Title.test.js
@@ -80,6 +80,7 @@
                ],
                invalid: [
                        '',
+                       ':',
                        '__  __',
                        '  __  ',
                        // Bad characters forbidden regardless of 
wgLegalTitleChars

-- 
To view, visit https://gerrit.wikimedia.org/r/99674
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I574168c9ed281c535901c36dea7c179a4e794d20
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Umherirrender <[email protected]>
Gerrit-Reviewer: Alex Monk <[email protected]>
Gerrit-Reviewer: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: Brion VIBBER <[email protected]>
Gerrit-Reviewer: Daniel Friesen <[email protected]>
Gerrit-Reviewer: Jack Phoenix <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: Parent5446 <[email protected]>
Gerrit-Reviewer: Platonides <[email protected]>
Gerrit-Reviewer: Tim Starling <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to