Merge "Fix mw.util.getUrl when given empty title with fragment"
This commit is contained in:
commit
4b65affbc7
3 changed files with 23 additions and 8 deletions
|
|
@ -158,7 +158,11 @@ util = {
|
|||
if ( params ) {
|
||||
query = $.param( params );
|
||||
}
|
||||
if ( query ) {
|
||||
|
||||
if ( !title && fragment ) {
|
||||
// If only a fragment was given, make a fragment-only link (T288415)
|
||||
url = '';
|
||||
} else if ( query ) {
|
||||
url = title ?
|
||||
util.wikiScript() + '?title=' + util.wikiUrlencode( title ) + '&' + query :
|
||||
util.wikiScript() + '?' + query;
|
||||
|
|
@ -168,7 +172,7 @@ util = {
|
|||
}
|
||||
|
||||
// Append the encoded fragment
|
||||
if ( fragment && fragment.length ) {
|
||||
if ( fragment ) {
|
||||
url += '#' + util.escapeIdForLink( fragment );
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -379,6 +379,17 @@ class TitleMethodsTest extends MediaWikiLangTestCase {
|
|||
'Goatificatiön'
|
||||
];
|
||||
|
||||
yield 'Fragment only (query is ignored)' => [
|
||||
'#Goatificatiön',
|
||||
NS_MAIN,
|
||||
'',
|
||||
'Goatificatiön',
|
||||
'',
|
||||
[
|
||||
'a' => 1,
|
||||
]
|
||||
];
|
||||
|
||||
yield 'Unknown interwiki with fragment' => [
|
||||
'https://xx.wiki.test/wiki/xyzzy:Goats#Goatificatiön',
|
||||
NS_MAIN,
|
||||
|
|
|
|||
|
|
@ -210,10 +210,10 @@
|
|||
assert.strictEqual( href, '/wiki/Sandbox', 'title with empty query string' );
|
||||
|
||||
href = util.getUrl( '#Fragment' );
|
||||
assert.strictEqual( href, '/wiki/#Fragment', 'empty title with fragment' );
|
||||
assert.strictEqual( href, '#Fragment', 'empty title with fragment' );
|
||||
|
||||
href = util.getUrl( '#Fragment', { action: 'edit' } );
|
||||
assert.strictEqual( href, '/w/index.php?action=edit#Fragment', 'empty title with query string and fragment' );
|
||||
assert.strictEqual( href, '#Fragment', 'empty title with query string and fragment' );
|
||||
|
||||
mw.util.setOptionsForTest( { FragmentMode: [ 'legacy' ] } );
|
||||
href = util.getUrl( 'Foo:Sandbox \xC4#Fragment \xC4', { action: 'edit' } );
|
||||
|
|
@ -227,12 +227,12 @@
|
|||
assert.strictEqual( href, '/w/index.php?title=Foo:%2523&action=edit#Fragment', 'title containing %23 (#), fragment, and a query string' );
|
||||
|
||||
mw.util.setOptionsForTest( { FragmentMode: [ 'legacy' ] } );
|
||||
href = util.getUrl( '#+&=:;@$-_.!*/[]<>\'§', { action: 'edit' } );
|
||||
assert.strictEqual( href, '/w/index.php?action=edit#.2B.26.3D:.3B.40.24-_..21.2A.2F.5B.5D.3C.3E.27.C2.A7', 'fragment with various characters' );
|
||||
href = util.getUrl( 'Sandbox#+&=:;@$-_.!*/[]<>\'§', { action: 'edit' } );
|
||||
assert.strictEqual( href, '/w/index.php?title=Sandbox&action=edit#.2B.26.3D:.3B.40.24-_..21.2A.2F.5B.5D.3C.3E.27.C2.A7', 'fragment with various characters' );
|
||||
|
||||
mw.util.setOptionsForTest( { FragmentMode: [ 'html5' ] } );
|
||||
href = util.getUrl( '#+&=:;@$-_.!*/[]<>\'§', { action: 'edit' } );
|
||||
assert.strictEqual( href, '/w/index.php?action=edit#+&=:;@$-_.!*/[]<>\'§', 'fragment with various characters' );
|
||||
href = util.getUrl( 'Sandbox#+&=:;@$-_.!*/[]<>\'§', { action: 'edit' } );
|
||||
assert.strictEqual( href, '/w/index.php?title=Sandbox&action=edit#+&=:;@$-_.!*/[]<>\'§', 'fragment with various characters' );
|
||||
} );
|
||||
|
||||
QUnit.test( 'wikiScript', function ( assert ) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue