User: Don't fail mysteriously when passing a User object to idFromName()
authorRoan Kattouw <roan.kattouw@gmail.com>
Wed, 31 Oct 2018 22:38:07 +0000 (15:38 -0700)
committerRoan Kattouw <roan.kattouw@gmail.com>
Wed, 31 Oct 2018 22:38:07 +0000 (15:38 -0700)
If $name is a User object, some code magically works because the object
gets converted to a string, but other code blows up because objects
aren't valid array keys. Prevent this from happening by explicitly
forcing $name to be a string.

Bug: T208469
Change-Id: Icc9ebec93d18609605e2633ccd23b90478e05e51

includes/user/User.php

index 11cfd49..f0b2c57 100644 (file)
@@ -909,6 +909,8 @@ class User implements IDBAccessObject, UserIdentity {
         * @return int|null The corresponding user's ID, or null if user is nonexistent
         */
        public static function idFromName( $name, $flags = self::READ_NORMAL ) {
+               // Don't explode on self::$idCacheByName[$name] if $name is not a string but e.g. a User object
+               $name = (string)$name;
                $nt = Title::makeTitleSafe( NS_USER, $name );
                if ( is_null( $nt ) ) {
                        // Illegal name