// that starts with "#". Before PHP 7 (and still on HHVM) substr() would
// return false if the start offset is the end of the string.
// On PHP 7+, it gracefully returns empty string instead.
- if ( $section === false ) {
- $section = '';
- }
- if ( $local ) {
- $sectionTitle = new TitleValue( NS_MAIN, '', $section );
- } else {
- $sectionTitle = $title->createFragmentTarget( $section );
- }
- if ( $sectionTitle ) {
+ if ( $section !== '' && $section !== false ) {
+ if ( $local ) {
+ $sectionTitle = new TitleValue( NS_MAIN, '', $section );
+ } else {
+ $sectionTitle = $title->createFragmentTarget( $section );
+ }
$auto = Linker::makeCommentLink(
- $sectionTitle, $wgLang->getArrow() . $wgLang->getDirMark() . $sectionText,
- $wikiId, 'noclasses'
+ $sectionTitle,
+ $wgLang->getArrow() . $wgLang->getDirMark() . $sectionText,
+ $wikiId,
+ 'noclasses'
);
}
}
"/* [[linkie?]] */",
],
[
- '<span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage" title="Special:BlankPage">→</a>: </span> // Edit via via</span>',
+ '<span dir="auto"><span class="autocomment">: </span> // Edit via via</span>',
// Regression test for T222857
"/* */ // Edit via via",
],
"/* autocomment */",
null
],
+ [
+ '',
+ "/* */",
+ false, true
+ ],
+ [
+ '',
+ "/* */",
+ null
+ ],
+ [
+ '<span dir="auto"><span class="autocomment">[[</span></span>',
+ "/* [[ */",
+ false, true
+ ],
+ [
+ '<span dir="auto"><span class="autocomment">[[</span></span>',
+ "/* [[ */",
+ null
+ ],
+ [
+ "foo <span dir=\"auto\"><span class=\"autocomment\"><a href=\"#.23\">→[[#_\t_]]</a></span></span>",
+ "foo /* [[#_\t_]] */",
+ false, true
+ ],
+ [
+ "foo <span dir=\"auto\"><span class=\"autocomment\"><a href=\"#_.09\">#_\t_</a></span></span>",
+ "foo /* [[#_\t_]] */",
+ null
+ ],
[
'<span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→autocomment</a></span></span>',
"/* autocomment */",
'X' . str_repeat( 'x', 251 ) ],
// Test decoding and normalization
[ '"ñ"', NS_MAIN, 'en', new TitleValue( NS_MAIN, '"ñ"' ) ],
+ [ 'X#ñ', NS_MAIN, 'en', new TitleValue( NS_MAIN, 'X', 'ñ' ) ],
+ // target section parsing
+ 'empty fragment' => [ 'X#', NS_MAIN, 'en', new TitleValue( NS_MAIN, 'X' ) ],
+ 'double hash' => [ 'X##', NS_MAIN, 'en', new TitleValue( NS_MAIN, 'X', '#' ) ],
+ 'fragment with hash' => [ 'X#z#z', NS_MAIN, 'en', new TitleValue( NS_MAIN, 'X', 'z#z' ) ],
+ 'fragment with space' => [ 'X#z z', NS_MAIN, 'en', new TitleValue( NS_MAIN, 'X', 'z z' ) ],
+ 'fragment with percent' => [ 'X#z%z', NS_MAIN, 'en', new TitleValue( NS_MAIN, 'X', 'z%z' ) ],
+ 'fragment with amp' => [ 'X#z&z', NS_MAIN, 'en', new TitleValue( NS_MAIN, 'X', 'z&z' ) ],
];
}