From 2b95bf3a483ee65383f1ac97bfca92a24dcbc6f6 Mon Sep 17 00:00:00 2001 From: Timothy Gu Date: Mon, 13 Feb 2017 23:12:19 -0800 Subject: [PATCH 1/2] url: fix handling of ? in URLSearchParams creation Fixes: https://github.com/nodejs/node/issues/11093 --- lib/internal/url.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/internal/url.js b/lib/internal/url.js index a37b9bf488f207..49f70668ab2bff 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -97,12 +97,11 @@ function onParseComplete(flags, protocol, username, password, ctx.query = query; ctx.fragment = fragment; ctx.host = host; - if (this[searchParams]) { // invoked from href setter - initSearchParams(this[searchParams], query); - } else { - this[searchParams] = new URLSearchParams(query); + if (!this[searchParams]) { // invoked from URL constructor + this[searchParams] = new URLSearchParams(); + this[searchParams][context] = this; } - this[searchParams][context] = this; + initSearchParams(this[searchParams], query); } // Reused by URL constructor and URL#href setter. From a8d9ca308d2e5d3649a82258a29606a6e6fff8a1 Mon Sep 17 00:00:00 2001 From: Timothy Gu Date: Mon, 13 Feb 2017 23:13:14 -0800 Subject: [PATCH 2/2] test, url: re-enable certain WPT tests --- test/parallel/test-whatwg-url-constructor.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/parallel/test-whatwg-url-constructor.js b/test/parallel/test-whatwg-url-constructor.js index a8a8667fc47021..ffcc022d3149b5 100644 --- a/test/parallel/test-whatwg-url-constructor.js +++ b/test/parallel/test-whatwg-url-constructor.js @@ -119,22 +119,22 @@ function runURLSearchParamTests() { // And in the other direction, altering searchParams propagates // back to 'search'. - // searchParams.append('i', ' j ') + searchParams.append('i', ' j ') // assert_equals(url.search, '?e=f&g=h&i=+j+') // assert_equals(url.searchParams.toString(), 'e=f&g=h&i=+j+') - // assert_equals(searchParams.get('i'), ' j ') + assert_equals(searchParams.get('i'), ' j ') - // searchParams.set('e', 'updated') + searchParams.set('e', 'updated') // assert_equals(url.search, '?e=updated&g=h&i=+j+') - // assert_equals(searchParams.get('e'), 'updated') + assert_equals(searchParams.get('e'), 'updated') - // var url2 = bURL('http://example.org/file??a=b&c=d') - // assert_equals(url2.search, '??a=b&c=d') - // assert_equals(url2.searchParams.toString(), '%3Fa=b&c=d') + var url2 = bURL('http://example.org/file??a=b&c=d') + assert_equals(url2.search, '??a=b&c=d') + assert_equals(url2.searchParams.toString(), '%3Fa=b&c=d') - // url2.href = 'http://example.org/file??a=b' - // assert_equals(url2.search, '??a=b') - // assert_equals(url2.searchParams.toString(), '%3Fa=b') + url2.href = 'http://example.org/file??a=b' + assert_equals(url2.search, '??a=b') + assert_equals(url2.searchParams.toString(), '%3Fa=b') }, 'URL.searchParams and URL.search setters, update propagation') } runURLSearchParamTests()