Krinkle has uploaded a new change for review. https://gerrit.wikimedia.org/r/133252
Change subject: mediawiki.util: Decode parentheses and bang in wikiUrlencode ...................................................................... mediawiki.util: Decode parentheses and bang in wikiUrlencode Matches behaviour of wfUrlencode() and creates prettier urls. Change-Id: I9b3ecda19f743cd87e790d99d50dd6b730e5ee21 --- M resources/src/mediawiki/mediawiki.util.js M tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js 2 files changed, 33 insertions(+), 4 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/52/133252/1 diff --git a/resources/src/mediawiki/mediawiki.util.js b/resources/src/mediawiki/mediawiki.util.js index 298415c..e2fa123 100644 --- a/resources/src/mediawiki/mediawiki.util.js +++ b/resources/src/mediawiki/mediawiki.util.js @@ -60,14 +60,29 @@ /** * Encode page titles for use in a URL + * * We want / and : to be included as literal characters in our title URLs - * as they otherwise fatally break the title + * as they otherwise fatally break the title. + * + * The others are decoded because we can, it's prettier and matches behaviour + * of `wfUrlencode` in PHP. * * @param {string} str String to be encoded. */ wikiUrlencode: function ( str ) { return util.rawurlencode( str ) - .replace( /%20/g, '_' ).replace( /%3A/g, ':' ).replace( /%2F/g, '/' ); + .replace( /%20/g, '_' ) + // wfUrlencode replacements + .replace( /%3B/g, ';' ) + .replace( /%40/g, '@' ) + .replace( /%24/g, '$' ) + .replace( /%21/g, '!' ) + .replace( /%2A/g, '*' ) + .replace( /%28/g, '(' ) + .replace( /%29/g, ')' ) + .replace( /%2C/g, ',' ) + .replace( /%2F/g, '/' ) + .replace( /%3A/g, ':' ); }, /** diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js b/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js index b2587be..1526679 100644 --- a/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js +++ b/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js @@ -17,8 +17,22 @@ assert.equal( mw.util.rawurlencode( 'Test:A & B/Here' ), 'Test%3AA%20%26%20B%2FHere' ); } ); - QUnit.test( 'wikiUrlencode', 1, function ( assert ) { + QUnit.test( 'wikiUrlencode', 10, function ( assert ) { assert.equal( mw.util.wikiUrlencode( 'Test:A & B/Here' ), 'Test:A_%26_B/Here' ); + // See also wfUrlencodeTest.php#provideURLS + $.each( { + '+': '%2B', + '&': '%26', + '=': '%3D', + ':': ':', + ';@$-_.!*': ';@$-_.!*', + '/': '/', + '[]': '%5B%5D', + '<>': '%3C%3E', + '\'': '%27' + }, function ( input, output ) { + assert.equal( mw.util.wikiUrlencode( input ), output ); + } ); } ); QUnit.test( 'getUrl', 4, function ( assert ) { @@ -30,7 +44,7 @@ assert.equal( href, '/wiki/Sandbox', 'Simple title; Get link for "Sandbox"' ); href = mw.util.getUrl( 'Foo:Sandbox ? 5+5=10 ! (test)/subpage' ); - assert.equal( href, '/wiki/Foo:Sandbox_%3F_5%2B5%3D10_%21_%28test%29/subpage', + assert.equal( href, '/wiki/Foo:Sandbox_%3F_5%2B5%3D10_!_(test)/subpage', 'Advanced title; Get link for "Foo:Sandbox ? 5+5=10 ! (test)/subpage"' ); href = mw.util.getUrl(); -- To view, visit https://gerrit.wikimedia.org/r/133252 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I9b3ecda19f743cd87e790d99d50dd6b730e5ee21 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Krinkle <krinklem...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits