- $title = Title::makeTitleSafe( NS_USER, $value );
- if ( $title === null || $title->hasFragment() ) {
+ $titleObj = Title::makeTitleSafe( NS_USER, $value );
+
+ if ( $titleObj ) {
+ $value = $titleObj->getText();
+ }
+
+ if (
+ !User::isValidUserName( $value ) &&
+ // We allow ranges as well, for blocks.
+ !IP::isIPAddress( $value ) &&
+ // See comment for User::isIP. We don't just call that function
+ // here because it also returns true for things like
+ // 300.300.300.300 that are neither valid usernames nor valid IP
+ // addresses.
+ !preg_match(
+ '/^' . RE_IP_BYTE . '\.' . RE_IP_BYTE . '\.' . RE_IP_BYTE . '\.xxx$/',
+ $value
+ )
+ ) {