Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

Add URLSearchParams.prototype.sort() #135

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions tests/url_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,15 @@ QUnit.test('Parameter Mutation', function(assert) {
url.searchParams.set('b', '3');
assert.deepEqual(url.searchParams.getAll('b'), ['3']);
assert.equal(url.href, 'http://example.com/?a=1&b=3&c=1');

url.href = 'http://example.com?c=1&a=2&a=4&b=3';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if these tests belong in this section.

url.searchParams.sort();
assert.equal(url.search, '?a=2&a=4&b=3&c=1');

// Preserving the relative order
url.href = 'http://example.com?c=1&a=4&a=2&b=3';
url.searchParams.sort();
assert.equal(url.search, '?a=4&a=2&b=3&c=1');
});

QUnit.test('Parameter Encoding', function(assert) {
Expand Down
8 changes: 8 additions & 0 deletions url.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,14 @@
}, writable: true, enumerable: true, configurable: true
},

sort: {
value: function () {
this._list.sort(function(pair1, pair2) {
return pair1.name.localeCompare(pair2.name);
});
}, writable: true, enumerable: true, configurable: true
},

toString: {
value: function () {
return urlencoded_serialize(this._list);
Expand Down