Title: fix: URLSearchParams construction and iteration spec compliance by adrian-niculescu · Pull Request #1970 · NativeScript/android · GitHub
Open Graph Title: fix: URLSearchParams construction and iteration spec compliance by adrian-niculescu · Pull Request #1970 · NativeScript/android
X Title: fix: URLSearchParams construction and iteration spec compliance by adrian-niculescu · Pull Request #1970 · NativeScript/android
Description: While chasing a failing backend request in our app we noticed it was hitting a URL that looked like this: https://api.example.com/items?[object+Object]= The culprit was an innocent new URLSearchParams({ limit: "50", cursor: "abc123" }). The binding only handles the string init form, so any object passed to the constructor gets stringified to "[object Object]" and the whole query collapses into one bogus key. The same code works in browsers and Node, which made it a fun one to track down. This reworks the constructor to follow the WebIDL init dispatch from the URL spec: a plain object is read as a record (own enumerable keys in order; a Symbol key throws), an iterable (Array, Map, Set, another URLSearchParams, generators) is read as a sequence of pairs (with IteratorClose on abrupt completion, and a TypeError for a pair whose length isn't 2), other primitives and null coerce to a USVString and get parsed (a Symbol throws; null parses as the string "null", matching the whatwg-url reference implementation), and undefined produces empty params (the IDL default). Writing tests for that surfaced a few more spec gaps, also fixed here: entries()/keys()/values() returned plain arrays, and there was no @@iterator, so for..of, spread, and the new URLSearchParams(other) copy form didn't work. They now return live ES iterators per spec, with @@iterator aliasing entries. This also fixes a duplicate-key bug: the old get_keys()+get() walk returned the first value for every occurrence of a repeated key. get() returns null for a missing name instead of undefined (one existing test asserted undefined and was updated to match the spec). delete(name, value) and has(name, value) honor the optional value argument, which ada already exposes. An explicit undefined value is treated as omitted, matching WPT. The URLSearchParams test group now has 49 specs covering all of the above. Full suite run on an emulator via runtests: 513 tests, 0 failures. iOS counterpart: NativeScript/ios#388. Update after review: every name and value argument across get/getAll/has/delete/append/set now goes through the same USVString coercion (a Symbol throws), entries()/keys()/values() and the iterator's next() brand-check their receivers, and GetPointer no longer reads an internal field from objects that have none (entries.call({}) used to be an out-of-bounds read). A second pass against the IDL and the whatwg-url reference implementation aligned three more corners: new URLSearchParams(null) parses as the string "null" instead of being treated as empty (the union conversion has no null special case; WPT does not cover it and Node is the outlier), an enumerable Symbol key in a record init throws, and the remaining members (get/getAll/has/append/set/delete/forEach/sort/toString/size) brand-check their receiver like the iterator methods. Summary by CodeRabbit Bug Fixes Iterators (entries/keys/values/default) now behave per spec: live, have correct identity/branding, preserve duplicates, close on errors, and throw on illegal invocation; get() returns null for missing keys. Improvements Constructor accepts records, arrays/pairs, Maps/Sets, generic iterables, primitives, and strips leading ?; delete()/has() support value-based matching with proper coercion and explicit-undefined handling. Tests Expanded coverage for iterators, constructor inputs, edge cases, and error conditions.
Open Graph Description: While chasing a failing backend request in our app we noticed it was hitting a URL that looked like this: https://api.example.com/items?[object+Object]= The culprit was an innocent new URLSearchPa...
X Description: While chasing a failing backend request in our app we noticed it was hitting a URL that looked like this: https://api.example.com/items?[object+Object]= The culprit was an innocent new URLSearchPa...
Opengraph URL: https://github.com/NativeScript/android/pull/1970
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:6b9881eb-2c1e-6c81-682b-78219c13b1e1 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | D6A4:3D8CBB:1B0AC60:23A5E89:6B014BEF |
| html-safe-nonce | e4b8056e877ee6341ce22c25e289704c50373203f57b930848fb1f8a0bf65d0c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENkE0OjNEOENCQjoxQjBBQzYwOjIzQTVFODk6NkIwMTRCRUYiLCJ2aXNpdG9yX2lkIjoiMjE3MDQ5NDQ3ODI0OTQ0NjM4MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | b443fd8e578a0fbf31e508927aa508d742df936b0e435e855a78ff88c3d8796e |
| hovercard-subject-tag | pull_request:3855011882 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/NativeScript/android/pull/1970/files |
| twitter:image | https://avatars.githubusercontent.com/u/15037449?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/15037449?s=400&v=4 |
| og:image:alt | While chasing a failing backend request in our app we noticed it was hitting a URL that looked like this: https://api.example.com/items?[object+Object]= The culprit was an innocent new URLSearchPa... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/NativeScript/android git https://github.com/NativeScript/android.git |
| octolytics-dimension-user_id | 7392261 |
| octolytics-dimension-user_login | NativeScript |
| octolytics-dimension-repository_id | 29137950 |
| octolytics-dimension-repository_nwo | NativeScript/android |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 29137950 |
| octolytics-dimension-repository_network_root_nwo | NativeScript/android |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width