-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backport-of: #11098 Fixes: #10760 Ref: whatwg/url#26 Ref: whatwg/url#199 Ref: web-platform-tests/wpt#4531
- Loading branch information
1 parent
5a2db15
commit c25c16c
Showing
3 changed files
with
174 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const { URL, URLSearchParams } = require('url'); | ||
const { test, assert_array_equals } = common.WPT; | ||
|
||
/* eslint-disable */ | ||
/* WPT Refs: | ||
https://github.com/w3c/web-platform-tests/blob/5903e00e77e85f8bcb21c73d1d7819fcd04763bd/url/urlsearchparams-sort.html | ||
License: http://www.w3.org/Consortium/Legal/2008/04-testsuite-copyright.html | ||
*/ | ||
[ | ||
{ | ||
"input": "z=b&a=b&z=a&a=a", | ||
"output": [["a", "b"], ["a", "a"], ["z", "b"], ["z", "a"]] | ||
}, | ||
{ | ||
"input": "\uFFFD=x&\uFFFC&\uFFFD=a", | ||
"output": [["\uFFFC", ""], ["\uFFFD", "x"], ["\uFFFD", "a"]] | ||
}, | ||
{ | ||
"input": "ffi&🌈", // 🌈 > code point, but < code unit because two code units | ||
"output": [["🌈", ""], ["ffi", ""]] | ||
}, | ||
{ | ||
"input": "é&e\uFFFD&e\u0301", | ||
"output": [["e\u0301", ""], ["e\uFFFD", ""], ["é", ""]] | ||
}, | ||
{ | ||
"input": "z=z&a=a&z=y&a=b&z=x&a=c&z=w&a=d&z=v&a=e&z=u&a=f&z=t&a=g", | ||
"output": [["a", "a"], ["a", "b"], ["a", "c"], ["a", "d"], ["a", "e"], ["a", "f"], ["a", "g"], ["z", "z"], ["z", "y"], ["z", "x"], ["z", "w"], ["z", "v"], ["z", "u"], ["z", "t"]] | ||
} | ||
].forEach((val) => { | ||
test(() => { | ||
let params = new URLSearchParams(val.input), | ||
i = 0 | ||
params.sort() | ||
for(let param of params) { | ||
assert_array_equals(param, val.output[i]) | ||
i++ | ||
} | ||
}, "Parse and sort: " + val.input) | ||
|
||
test(() => { | ||
let url = new URL("?" + val.input, "https://example/") | ||
url.searchParams.sort() | ||
let params = new URLSearchParams(url.search), | ||
i = 0 | ||
for(let param of params) { | ||
assert_array_equals(param, val.output[i]) | ||
i++ | ||
} | ||
}, "URL parse and sort: " + val.input) | ||
}) | ||
/* eslint-enable */ | ||
|
||
// Tests below are not from WPT. | ||
;[ | ||
{ | ||
'input': 'z=a&=b&c=d', | ||
'output': [['', 'b'], ['c', 'd'], ['z', 'a']] | ||
} | ||
].forEach((val) => { | ||
test(() => { | ||
const params = new URLSearchParams(val.input); | ||
let i = 0; | ||
params.sort(); | ||
for (const param of params) { | ||
assert_array_equals(param, val.output[i]); | ||
i++; | ||
} | ||
}, 'Parse and sort: ' + val.input); | ||
|
||
test(() => { | ||
const url = new URL(`?${val.input}`, 'https://example/'); | ||
url.searchParams.sort(); | ||
const params = new URLSearchParams(url.search); | ||
let i = 0; | ||
for (const param of params) { | ||
assert_array_equals(param, val.output[i]); | ||
i++; | ||
} | ||
}, 'URL parse and sort: ' + val.input); | ||
}); |
c25c16c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This did not land with proper meta data and is breaking tooling