Repository navigation
Conversation
The `URLSearchParams` constructor built its pair list by calling `next()` on the input iterator and then reading `res.done`. It only checked for `null`/`undefined`, so a primitive iterator result was accepted. Web IDL's "create sequence from iterable" uses `IteratorStepValue`, which calls `IteratorNext`. `IteratorNext` throws a TypeError when the iterator result is not an Object, and it does so before `done` is read. A primitive result whose prototype happens to expose `done` was therefore treated as a completed iteration instead of raising a TypeError. Check that the iterator result is an object before reading `done`, so the constructor matches the Web IDL sequence conversion. Fixes denoland#37117
Author
|
Verified against a real Deno 2.9.8 binary (v8 15.0.245.2-rusty). Running the issue's reproduction on the stock runtime reproduces the bug: Node.js 26 rejects it: Running the patched constructor logic from So the patched path throws before |
NetOpWibby
pushed a commit
to theende/ende
that referenced
this pull request
Nov 7, 2026
The `URLSearchParams` constructor built its pair list by calling `next()` on the input iterator and then reading `res.done`. It only checked for `null`/`undefined`, so a primitive iterator result was accepted. Web IDL's "create sequence from iterable" uses `IteratorStepValue`, which calls `IteratorNext`. `IteratorNext` throws a TypeError when the iterator result is not an Object, and it does so before `done` is read. A primitive result whose prototype happens to expose `done` was therefore treated as a completed iteration instead of raising a TypeError. Check that the iterator result is an object before reading `done`, so the constructor matches the Web IDL sequence conversion. Ende change: upstream's `typeof res !== "object"` also rejected functions, which are Objects; they are accepted again, with a test. (cherry picked from commit 4225ff7d0ae7fb2e4d6c95412e51bb48693278b2) Upstream: denoland/deno#37124
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix(ext/web): reject non-object iterator results in URLSearchParams
The
URLSearchParamsconstructor built its pair list by callingnext()on the input iterator and then readingres.done. It only checked fornull/undefined, so a primitive iterator result was accepted.Web IDL's "create sequence from iterable" uses
IteratorStepValue, which callsIteratorNext.IteratorNextthrows a TypeError when the iterator result is not an Object, and it does so beforedoneis read. A primitive result whose prototype happens to exposedonewas therefore treated as a completed iteration instead of raising a TypeError.Check that the iterator result is an object before reading
done, so the constructor matches the Web IDL sequence conversion.This matches the behavior of Node.js 26.13.0.
Fixes #37117
Testing
urlSearchParamsRejectsNonObjectIteratorResulttotests/unit/url_search_params_test.ts. It asserts that a non-object iterator result raises aTypeErrorand thatdoneis never read on the primitive result.ext/web/00_url.js: without the fix the constructor accepts the primitive result and readsdoneonce; with the fix it throws aTypeErrorand readsdonezero times.Map, generator, and iterators that terminate withdone: true) produce identical results before and after the change.AI usage disclosure
This PR was prepared with AI assistance (Claude / Hermes). The reproduction came from the linked issue, the fix follows the Web IDL and ECMA-262 specifications cited above, and the change was verified by running the affected code path directly before and after the patch.