Bug 204127 - Inconsistent/lazy encoding of URL.searchParams
Summary: Inconsistent/lazy encoding of URL.searchParams
Status: RESOLVED INVALID
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore JavaScript (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2019-11-12 14:47 PST by Jim Heising
Modified: 2019-11-22 19:01 PST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jim Heising 2019-11-12 14:47:53 PST
DESCRIPTION:

When a window.URL object is created with a URL string that contains search params with non-url-safe characters, they will only be properly encoded after a call is made to any method on the searchParams member.

It seems like encoding of search parameters is done lazily, when it should probably be done at object construction time.

EXAMPLE:

> var myURL = new URL("https://test.com?param1=my{{bad}}param");
> console.log(myURL.toString());
> // Output: https://test.com/?param1=my{{bad}}param
> // Note how param1 is not properly encoded
>
> myURL.searchParams.sort(); // Doesn't seem matter what method is called— we choose sort here...
> console.log(myURL.toString());
> // Output: https://test.com/?param1=my%7B%7Bbad%7D%7Dparam
> // Note how param1 is now properly encoded
Comment 1 Jim Heising 2019-11-12 15:13:06 PST
It seems like one solution would be to call updateURL() (https://trac.webkit.org/browser/webkit/trunk/Source/WebCore/html/URLSearchParams.cpp#L139) during object construction.
Comment 2 Radar WebKit Bug Importer 2019-11-16 00:11:42 PST
<rdar://problem/57251311>
Comment 3 Alex Christensen 2019-11-22 19:01:49 PST
Our behavior here matches the behavior of Chrome and Firefox and the URL specification.  For whatever reason, https://url.spec.whatwg.org/#concept-urlencoded-byte-serializer uses a different set than https://url.spec.whatwg.org/#query-state step 5.  Because the behavior of all browsers agrees, you're going to have a hard time changing the specification.