[General] [Fixed] - Fix URLSearchParams.keys() returning only unique keys#56361
[General] [Fixed] - Fix URLSearchParams.keys() returning only unique keys#56361Nedunchezhiyan-M wants to merge 1 commit intofacebook:mainfrom
Conversation
The WHATWG URL spec states that URLSearchParams.keys() must yield one
entry per name-value pair, meaning duplicate names appear multiple times.
The previous implementation returned Map.keys() directly, which yields each
key only once regardless of how many values are stored under it. This caused
keys() to be inconsistent with values() and entries(), both of which already
handle duplicates correctly.
Updated keys() to use a generator that yields each key once per associated
value, matching the approach already used by values() and entries().
Test plan: Added a test asserting that keys() on URLSearchParams with
duplicate key entries ('key1', 'key1', 'key2') returns all three names.
Changelog:
[General] [Fixed] - Fix URLSearchParams.keys() returning only unique keys instead of all name-value pair names
|
Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
f1842fb to
420739c
Compare
Summary:
The
URLSearchParams.keys()method was returningMap.keys()directly, which yields each unique key only once. The WHATWG URL spec requireskeys()to return an iterator that yields one entry per name-value pair, meaning duplicate names must appear multiple times.For example, given
new URLSearchParams('a=1&a=2&b=3'):[...params.keys()]returns['a', 'b'](unique keys only)[...params.keys()]returns['a', 'a', 'b'](one per pair, as specified)This made
keys()inconsistent withvalues()andentries(), both of which already handle duplicates correctly using generator functions. The fix applies the same generator pattern tokeys().Changelog:
[General] [Fixed] - Fix URLSearchParams.keys() returning only unique keys instead of all name-value pair names
Test Plan:
Added a test asserting that
keys()on aURLSearchParamsinstance with duplicate key entries yields all names including duplicates:Verification: The fix is consistent with browser behaviour: