// be refactored to avoid this.
$parts = $this->splitTitleString( $filteredText, $defaultNamespace );
- // Relative fragment links are not supported by TitleValue
- if ( $parts['dbkey'] === '' ) {
+ // Fragment-only is okay, but only with no namespace
+ if ( $parts['dbkey'] === '' &&
+ ( $parts['fragment'] === '' || $parts['namespace'] !== NS_MAIN ) ) {
throw new MalformedTitleException( 'title-invalid-empty', $text );
}
// Sanity check, no full validation or normalization applied here!
Assert::parameter( !preg_match( '/^_|[ \r\n\t]|_$/', $dbkey ), '$dbkey',
"invalid DB key '$dbkey'" );
- Assert::parameter( $dbkey !== '', '$dbkey', 'should not be empty' );
+ Assert::parameter( $dbkey !== '' || ( $fragment !== '' && $namespace === NS_MAIN ),
+ '$dbkey', 'should not be empty unless namespace is main and fragment is non-empty' );
$this->namespace = $namespace;
$this->dbkey = $dbkey;
public function goodConstructorProvider() {
return [
+ [ NS_MAIN, '', 'fragment', '', true, false ],
[ NS_USER, 'TestThis', 'stuff', '', true, false ],
[ NS_USER, 'TestThis', '', 'baz', false, true ],
];
[ NS_MAIN, 5, 'fragment', '' ],
[ NS_MAIN, null, 'fragment', '' ],
- [ NS_MAIN, '', 'fragment', '' ],
+ [ NS_USER, '', 'fragment', '' ],
[ NS_MAIN, 'foo bar', '', '' ],
[ NS_MAIN, 'bar_', '', '' ],
[ NS_MAIN, '_foo', '', '' ],