summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Gu <timothygu99@gmail.com>2017-07-24 11:52:53 +0800
committerTimothy Gu <timothygu99@gmail.com>2017-08-01 11:58:15 +0800
commit57630adf90a347b47315614a63b750d4838911ae (patch)
tree57b349d5ce6d28f44eaa3bff9c1604959681c286
parent6e79076feeb04a18253c0dc623307523819142d3 (diff)
downloadandroid-node-v8-57630adf90a347b47315614a63b750d4838911ae.tar.gz
android-node-v8-57630adf90a347b47315614a63b750d4838911ae.tar.bz2
android-node-v8-57630adf90a347b47315614a63b750d4838911ae.zip
url: update sort() behavior with no params
PR-URL: https://github.com/nodejs/node/pull/14185 Refs: https://github.com/whatwg/url/pull/336 Reviewed-By: Michaƫl Zasso <targos@protonmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
-rw-r--r--lib/internal/url.js9
-rw-r--r--test/parallel/test-whatwg-url-searchparams-delete.js17
-rw-r--r--test/parallel/test-whatwg-url-searchparams-sort.js11
3 files changed, 29 insertions, 8 deletions
diff --git a/lib/internal/url.js b/lib/internal/url.js
index 6048777cfd..95b5e9c5fd 100644
--- a/lib/internal/url.js
+++ b/lib/internal/url.js
@@ -1076,12 +1076,11 @@ defineIDLClass(URLSearchParams.prototype, 'URLSearchParams', {
sort() {
const a = this[searchParams];
const len = a.length;
- if (len <= 2) {
- return;
- }
- // arbitrary number found through testing
- if (len < 100) {
+ if (len <= 2) {
+ // Nothing needs to be done.
+ } else if (len < 100) {
+ // 100 is found through testing.
// Simple stable in-place insertion sort
// Derived from v8/src/js/array.js
for (var i = 2; i < len; i += 2) {
diff --git a/test/parallel/test-whatwg-url-searchparams-delete.js b/test/parallel/test-whatwg-url-searchparams-delete.js
index 6e733fd944..2969f51a73 100644
--- a/test/parallel/test-whatwg-url-searchparams-delete.js
+++ b/test/parallel/test-whatwg-url-searchparams-delete.js
@@ -8,7 +8,7 @@ const { test, assert_equals, assert_true, assert_false } =
/* The following tests are copied from WPT. Modifications to them should be
upstreamed first. Refs:
- https://github.com/w3c/web-platform-tests/blob/8791bed/url/urlsearchparams-delete.html
+ https://github.com/w3c/web-platform-tests/blob/70a0898763/url/urlsearchparams-delete.html
License: http://www.w3.org/Consortium/Legal/2008/04-testsuite-copyright.html
*/
/* eslint-disable */
@@ -42,6 +42,21 @@ test(function() {
params.delete('first');
assert_false(params.has('first'), 'Search params object has no "first" name');
}, 'Deleting appended multiple');
+
+test(function() {
+ var url = new URL('http://example.com/?param1&param2');
+ url.searchParams.delete('param1');
+ url.searchParams.delete('param2');
+ assert_equals(url.href, 'http://example.com/', 'url.href does not have ?');
+ assert_equals(url.search, '', 'url.search does not have ?');
+}, 'Deleting all params removes ? from URL');
+
+test(function() {
+ var url = new URL('http://example.com/?');
+ url.searchParams.delete('param1');
+ assert_equals(url.href, 'http://example.com/', 'url.href does not have ?');
+ assert_equals(url.search, '', 'url.search does not have ?');
+}, 'Removing non-existent param removes ? from URL');
/* eslint-enable */
// Tests below are not from WPT.
diff --git a/test/parallel/test-whatwg-url-searchparams-sort.js b/test/parallel/test-whatwg-url-searchparams-sort.js
index 406dceca2b..0e01c627ee 100644
--- a/test/parallel/test-whatwg-url-searchparams-sort.js
+++ b/test/parallel/test-whatwg-url-searchparams-sort.js
@@ -2,11 +2,11 @@
require('../common');
const { URL, URLSearchParams } = require('url');
-const { test, assert_array_equals } = require('../common/wpt');
+const { test, assert_equals, assert_array_equals } = require('../common/wpt');
/* The following tests are copied from WPT. Modifications to them should be
upstreamed first. Refs:
- https://github.com/w3c/web-platform-tests/blob/5903e00e77e85f8bcb21c73d1d7819fcd04763bd/url/urlsearchparams-sort.html
+ https://github.com/w3c/web-platform-tests/blob/70a0898763/url/urlsearchparams-sort.html
License: http://www.w3.org/Consortium/Legal/2008/04-testsuite-copyright.html
*/
/* eslint-disable */
@@ -53,6 +53,13 @@ const { test, assert_array_equals } = require('../common/wpt');
}
}, "URL parse and sort: " + val.input)
})
+
+test(function() {
+ const url = new URL("http://example.com/?")
+ url.searchParams.sort()
+ assert_equals(url.href, "http://example.com/")
+ assert_equals(url.search, "")
+}, "Sorting non-existent params removes ? from URL")
/* eslint-enable */
// Tests below are not from WPT.