Skip to content

fix: deprecation of url.parse#35

Open
Zamiell wants to merge 1 commit intojonschlinkert:masterfrom
Zamiell:fix-34
Open

fix: deprecation of url.parse#35
Zamiell wants to merge 1 commit intojonschlinkert:masterfrom
Zamiell:fix-34

Conversation

@Zamiell
Copy link

@Zamiell Zamiell commented Mar 11, 2026

Problem

Node.js v24 introduced DEP0169, a deprecation warning for url.parse():

(node:1234) [DEP0169] DeprecationWarning: url.parse() behavior is not standardized
and prone to errors that have security implications. Use the WHATWG URL API instead.

This library called url.parse() in two places, causing the warning to be emitted to stderr whenever the library was used. Downstream projects that assert on clean stderr (e.g. in tests) were broken as a
result.

Solution

Replace both url.parse() calls with the WHATWG URL API (new URL()):

  • The main url.parse(str) call is replaced by a new parseUrl() helper that uses new URL(str), with a fallback for non-standard strings that new URL() rejects (bare paths like user/repo#branch, git@ SSH
    URLs).
  • The secondary url.parse('http://' + ...) call used to extract the host from git@ URLs is replaced by a getGitAtHost() helper using new URL('http://' + ...).

One subtlety: for non-special scheme URLs without // (e.g. github:user/repo, foo:bar), the WHATWG URL API produces an "opaque path" with an empty host, whereas the legacy url.parse() treated the first path
segment as the host. The new parseUrl() replicates this behaviour explicitly — if there is no slash after the scheme (e.g. foo:bar), the token is treated as a hostname and path/pathname are set to null,
causing parse() to return null as before.

The url module import is removed entirely.

Testing

All 193 existing tests pass. The existing process.on('warning', ...) handler in the test suite now reliably catches any future regressions.

(Claude helped me write this PR.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant