When title contains only slashes, Title::getRootText() shouldn't return false
authorMartin Urbanec <martin.urbanec@wikimedia.cz>
Sat, 13 Jul 2019 22:27:43 +0000 (00:27 +0200)
committerMartin Urbanec <martin.urbanec@wikimedia.cz>
Sun, 14 Jul 2019 11:27:20 +0000 (13:27 +0200)
Otherwise, Title::makeTitleSafe() will return null, which
breaks the assumption that Title::makeTitleSafe() always
returns something meaningful for strings
returned by Title::getRootText().

Bug: T227816
Change-Id: If79a12bb8d23f1eafc10017d56c62566f39347ad

includes/Title.php
tests/phpunit/includes/TitleTest.php

index a956ca2..7e7153f 100644 (file)
@@ -1770,6 +1770,7 @@ class Title implements LinkTarget, IDBAccessObject {
                if (
                        !MediaWikiServices::getInstance()->getNamespaceInfo()->
                                hasSubpages( $this->mNamespace )
+                       || strtok( $this->getText(), '/' ) === false
                ) {
                        return $this->getText();
                }
index 4ffef02..5ecc663 100644 (file)
@@ -553,6 +553,10 @@ class TitleTest extends MediaWikiTestCase {
                        # Title, expected base, optional message
                        [ 'User:John_Doe/subOne/subTwo', 'John Doe' ],
                        [ 'User:Foo / Bar / Baz', 'Foo ' ],
+                       [ 'Talk:////', '////' ],
+                       [ 'Template:////', '////' ],
+                       [ 'Template:Foo////', 'Foo' ],
+                       [ 'Template:Foo////Bar', 'Foo' ],
                ];
        }