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.