Skip to content

fix: Replace deprecated url.parse() with WHATWG URL (DEP0169)#3124

Merged
lahirumaramba merged 1 commit into
firebase:v14from
kyungseopk1m:fix/url-parse-deprecation
May 27, 2026
Merged

fix: Replace deprecated url.parse() with WHATWG URL (DEP0169)#3124
lahirumaramba merged 1 commit into
firebase:v14from
kyungseopk1m:fix/url-parse-deprecation

Conversation

@kyungseopk1m

Copy link
Copy Markdown
Contributor

Closes #3118.

url.parse() is deprecated (DEP0169) and emits warnings on every cold start in serverless runtimes. This swaps the two call sites in BaseRequestConfigImpl.buildUrl() for the WHATWG URL constructor, matching the pattern @lahirumaramba used for validator.isURL() in #3061.

Changes

  • BaseRequestConfigImpl.buildUrl() returns URL instead of url.UrlWithStringQuery. The method is protected and only used by two subclasses inside the same file, so this is not a public surface change.
  • Both branches of buildUrl() now reuse a single new URL(fullUrl) instance instead of allocating one and re-parsing it via url.parse().
  • parsed.path is replaced with ${parsed.pathname}${parsed.search} so the request path on the wire stays byte-for-byte identical.
  • parsed.port is now string (always) rather than string | null. The existing if (!port) falsy check still picks up the empty case.

Behavior

For valid inputs the request URL is byte-for-byte identical. For malformed inputs the WHATWG parser is stricter than url.parse(): depending on the input shape it may either canonicalize the input differently (urlWithProtocol() always prepends https://, so e.g. //evil.com becomes https://evil.com/) or throw a TypeError. SDK-internal callers normalize their URLs before invoking, so well-formed usage is unaffected.

Out of scope

The transitive callers listed in #3118 (http-proxy-agent, teeny-request/agent-base, faye-websocket, @firebase/database-compat) live in separate repositories and need to be addressed there.

Verification

  • npx tsc --noEmit -p . — clean
  • npx eslint src/utils/api-request.ts — 0 warnings
  • npx mocha test/unit/utils/api-request.spec.ts --require ts-node/register — 199 passing
  • npx mocha test/unit/index.spec.ts --require ts-node/register — 6231 passing

No spec changes: existing api-request tests already cover explicit non-default ports (mockHost:8080), POST with entity body, GET path matching, and nock interceptor URL parsing — all of which exercise the changed code paths.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors src/utils/api-request.ts to replace the deprecated Node.js url module with the native URL API. Key changes include updating the buildUrl method to return a URL instance and modifying property accesses to use pathname and search instead of the non-existent path property. I have no feedback to provide.

@lahirumaramba lahirumaramba changed the base branch from main to v14 May 27, 2026 18:27
url.parse() is deprecated (DEP0169) and emits warnings on every cold
start in serverless runtimes. Migrate the two call sites in
BaseRequestConfigImpl.buildUrl() to the WHATWG URL constructor,
matching the pattern from firebase#3061.

The protected buildUrl() return type changes from url.UrlWithStringQuery
to URL. Both call sites are inside the same file. parsed.path is
replaced with ${parsed.pathname}${parsed.search} so the request path on
the wire stays byte-for-byte identical, and parsed.port is now string
(always); the existing if (!port) falsy check still catches the empty
case.

Fixes firebase#3118.
@lahirumaramba lahirumaramba force-pushed the fix/url-parse-deprecation branch from e878ef8 to 8344df7 Compare May 27, 2026 19:42
@lahirumaramba lahirumaramba changed the title fix(api-request): replace deprecated url.parse() with WHATWG URL (DEP0169) May 27, 2026

@lahirumaramba lahirumaramba left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution! LGTM!

@lahirumaramba lahirumaramba merged commit c9db870 into firebase:v14 May 27, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

2 participants