Handle $title === null in Title::newFromText
authorGergő Tisza <tgr.huwiki@gmail.com>
Thu, 26 Jul 2018 18:39:21 +0000 (20:39 +0200)
committerGergő Tisza <tgr.huwiki@gmail.com>
Thu, 26 Jul 2018 18:39:21 +0000 (20:39 +0200)
This relied on TitleCodec throwing MalformedTitleException in the
past, but that is fragile as other parts of the logic do not
expect null.

Bug: T200456
Change-Id: I1aca3971e2a9c0b1fe3adbcf34f3ee65b2271234

includes/Title.php

index b583554..f6bc947 100644 (file)
@@ -306,6 +306,10 @@ class Title implements LinkTarget {
        public static function newFromTextThrow( $text, $defaultNamespace = NS_MAIN ) {
                if ( is_object( $text ) ) {
                        throw new MWException( '$text must be a string, given an object' );
+               } elseif ( $text === null ) {
+                       // Legacy code relies on MalformedTitleException being thrown in this case
+                       // (happens when URL with no title in it is parsed). TODO fix
+                       throw new MalformedTitleException( 'title-invalid-empty' );
                }
 
                $titleCache = self::getTitleCache();