feat(stdlib): implement WHATWG Fetch Request/Response and URLPattern with regex runtime hardening - #26
Merged
Conversation
…with regex hardening - Implement WHATWG Request and Response standard compliance in node:http: - Full body decoders: .text(), .json(), .arrayBuffer(), .blob(), .bytes(), .formData() - Static constructors: Response.json(), Response.error(), Response.redirect() - Automatic multipart/form-data generation for FormData bodies with boundary - Request/Response clone() support and BodyInit normalization - Integration with fetch() returning WHATWG Response instances - Implement WHATWG / WinterCG URLPattern in node:urlpattern: - Pattern matching for 8 URL components (protocol, username, password, hostname, port, pathname, search, hash) - Named parameter captures (:id), wildcard captures (*), optional tokens (:param?), and custom regex constraints (:id(\\d+)) - BaseURL resolution and full input dictionary / string matching support - Export URLPattern in node:url and web global scope - Harden native POSIX regex runtime: - Add support for non-capturing groups (?:...) - Correct JS RegExp capture group index mapping in RegExp.exec - Return undefined sentinel for unmatched optional groups - Add comprehensive corpus test suites for request, response, and urlpattern - Update typescript-parity-report.md with verified 430/430 (100%) parity
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.
Overview
This PR completes WHATWG Fetch (
Request,Response,fetch) compliance innode:http, implements WHATWG / WinterCGURLPatterninnode:urlpatternandnode:url, and hardens POSIX regex runtime handling for non-capturing groups and JS capture indices.Key Changes
1. WHATWG Fetch (
Request&Response)RequestandResponse:.text(): Promise<string>.json(): Promise<unknown>.arrayBuffer(): Promise<ArrayBuffer>.blob(): Promise<Blob>.bytes(): Promise<Uint8Array>.formData(): Promise<FormData>(handlesmultipart/form-datawith boundary parser andapplication/x-www-form-urlencoded)FormDatabodies tomultipart/form-datawith randomly generated boundaries.BodyInitinputs (string,Blob,ArrayBuffer,Uint8Array,FormData,URLSearchParams).Response.json(data, init)Response.error()Response.redirect(url, status)Request.clone()andResponse.clone().fetch()integrated withRequest&Responsecontracts.2. WHATWG / WinterCG
URLPatternURLPatternininternal/typescriptgo/stdlib/urlpattern.tsper WHATWG URLPattern specification.protocol,username,password,hostname,port,pathname,search, andhash.:param), wildcards (*), optional tokens (:param?), and regex constraints (:id(\\d+)).test(), andexec()returning structuredURLPatternResult.node:url,node:urlpattern, and registered as an automatic web global.3. POSIX RegExp Runtime Hardening
(?:...)ininternal/runtime/native/regex/runtime.c.1 + js_group_countelements, skipping internal non-capturing groups.undefinedsentinel for unmatched optional groups (e.g.a(b)?con"ac").4. Corpus Tests & Documentation
internal/compiler/testdata/corpus/api/request.tscovering all body readers, methods, and headers.internal/compiler/testdata/corpus/api/response.tscovering status codes, body decoders, static constructors, and clones.internal/compiler/testdata/corpus/api/urlpattern.tsverifying path matching, named parameters, wildcards, and URL component extraction.docs/typescript-parity-report.mdmaintaining 430/430 (100.0%) parity.Verification
go test -count=1 ./...(All package tests passed, including corpus tests)go test -count=1 ./internal/typescriptgo/...(Passed)go run ./cmd/parity(430/430 100.0% passed)go build ./cmd/scriptgo(Passed)