Skip to content

url: Improve WHATWG URLSearchParams spec compliance

Checklist
  • make -j8 test (UNIX), or vcbuild test nosign (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added (WHATWG URL interface is still experimental and undocumented)
  • commit message follows commit guidelines
Affected core subsystem(s)

url, test

Description of change

This PR aims to improve the general compatibility of URLSearchParams class with WHATWG's URL Standard. Specifically, the PR consists of the following parts:

  • Make URLSearchParams constructor signature the same as the spec
  • Strip leading ? in URL#search's setter
  • Spec-compliant iterable interface
    • Implementation of keys, entries, and forEach methods
    • Use a dedicated URLSearchParamsIterator object instead of a generator function for @@iterator, per spec
  • Add tests from W3C's Web Platform Tests.
    • Some tests, e.g. the ones related to %20 vs +, are still commented out.

TODOs and points of discussion:

  • Make URLSearchParams public
  • Crediting W3C for the tests
  • It might be better for iterator creation to be made generic and shared for the entire code base.
  • Investigate the applicability of a "security check" as mandated by the spec for @@iterator, keys, values, and entries
  • Multiple deviations of querystring's behaviors with the WHATWG URL Standard
    • querystring does not parse empty values properly
    • Currently, querystring uses an implementation of encodeURIComponent to encode the query string. However, the application/x-www-form-urlencoded byte serializer disagrees on certain characters such as 0x20 (space; encodeURIComponent escapes it as %20 while querystring should serialize it to +), 0x27 (left paren; encodeURIComponent does not escape but querystring should), etc.
  • Is there a reason against making all values in the hashmap arrays?

Fixes: #9302 (closed)

Merge request reports

Loading