Merge "mediawiki.Uri: Support names of Object prototypes as keys in query"
This commit is contained in:
commit
926a0bfa50
2 changed files with 18 additions and 3 deletions
|
|
@ -276,7 +276,8 @@
|
|||
*/
|
||||
parse: function ( str, options ) {
|
||||
var q, matches,
|
||||
uri = this;
|
||||
uri = this,
|
||||
hasOwn = Object.prototype.hasOwnProperty;
|
||||
|
||||
// Apply parser regex and set all properties based on the result
|
||||
matches = parser[ options.strictMode ? 'strict' : 'loose' ].exec( str );
|
||||
|
|
@ -298,7 +299,7 @@
|
|||
|
||||
// If overrideKeys, always (re)set top level value.
|
||||
// If not overrideKeys but this key wasn't set before, then we set it as well.
|
||||
if ( options.overrideKeys || q[ k ] === undefined ) {
|
||||
if ( options.overrideKeys || !hasOwn.call( q, k ) ) {
|
||||
q[ k ] = v;
|
||||
|
||||
// Use arrays if overrideKeys is false and key was already seen before
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@
|
|||
} );
|
||||
} );
|
||||
|
||||
QUnit.test( 'Constructor( String[, Object ] )', 10, function ( assert ) {
|
||||
QUnit.test( 'Constructor( String[, Object ] )', 11, function ( assert ) {
|
||||
var uri;
|
||||
|
||||
uri = new mw.Uri( 'http://www.example.com/dir/?m=foo&m=bar&n=1', {
|
||||
|
|
@ -132,6 +132,20 @@
|
|||
strictMode: false
|
||||
} );
|
||||
assert.equal( uri.toString(), 'http://example.com/bar/baz', 'normalize URI without protocol or // in loose mode' );
|
||||
|
||||
/*jshint -W001 */
|
||||
uri = new mw.Uri( 'http://example.com/index.php?key=key&hasOwnProperty=hasOwnProperty&constructor=constructor&watch=watch' );
|
||||
assert.deepEqual(
|
||||
uri.query,
|
||||
{
|
||||
key: 'key',
|
||||
constructor: 'constructor',
|
||||
hasOwnProperty: 'hasOwnProperty',
|
||||
watch: 'watch'
|
||||
},
|
||||
'Keys in query strings support names of Object prototypes (bug T114344)'
|
||||
);
|
||||
/*jshint +W001 */
|
||||
} );
|
||||
|
||||
QUnit.test( 'Constructor( Object )', 3, function ( assert ) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue