Skip to content

refactor: migrate to URL.parse() - #450

Merged
stevenjoezhang merged 1 commit into
masterfrom
migrate-url-parse
Aug 13, 2026
Merged

refactor: migrate to URL.parse()#450
stevenjoezhang merged 1 commit into
masterfrom
migrate-url-parse

Conversation

@stevenjoezhang

@stevenjoezhang stevenjoezhang commented Aug 13, 2026

Copy link
Copy Markdown
Member

check list

  • Add test cases for the changes.
  • Passed the CI test.

Description

Migrate the remaining legacy url.parse() call sites to the non-throwing WHATWG URL.parse() API, now that hexo-util requires Node.js 22.1 or newer after #449.

  • Parse complete absolute URL inputs in encodeURL() and decodeURL(), while preserving the fast path for ordinary relative paths.
  • Replace new URL() exception handling with explicit null handling.
  • Use WHATWG hostname parsing in isExternalLink(), full_url_for(), and url_for().
  • Treat malformed URLs as fallback input instead of throwing, and support IPv6 site hosts correctly.

Issue resolved: hexojs/hexo#3846.

Additional information

Local checks:

  • TypeScript build and 266 tests on Node.js 22.1.0
  • TypeScript build and 266 tests on Node.js 24.15.0
  • TypeScript build and 266 tests on Node.js 26.7.0
  • npm run eslint
  • 100% line coverage for all five modified runtime files

@stevenjoezhang
stevenjoezhang marked this pull request as ready for review August 13, 2026 01:51

@SukkaW SukkaW 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.

BTW how benchmark shows?

@stevenjoezhang

Copy link
Copy Markdown
Member Author

@SukkaW I benchmarked hexo-util before and after this PR, with Node.js v26.7.0 and Apple M1 Pro, 32 GiB RAM. The results:

Workload Before After Change
encodeURL() — absolute URL 224,474 ops/s 235,755 ops/s +5.0%
encodeURL() — relative-path fast path 1,796,595 ops/s 1,803,873 ops/s +0.4%
decodeURL() — absolute URL 407,214 ops/s 444,515 ops/s +9.2%
decodeURL() — relative-path fast path 2,569,560 ops/s 2,558,090 ops/s −0.4%
isExternalLink() — cache miss 541,076 ops/s 674,181 ops/s +24.6%
full_url_for() — cache miss 170,467 ops/s 190,514 ops/s +11.8%
url_for() — cache miss 312,992 ops/s 365,563 ops/s +16.8%

The ±0.4% differences in the relative-path fast paths are within normal run-to-run variance, so those paths can be considered unchanged.

@stevenjoezhang
stevenjoezhang merged commit 96c20ce into master Aug 13, 2026
27 checks passed
@stevenjoezhang
stevenjoezhang deleted the migrate-url-parse branch August 13, 2026 08:09
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.

WHATWG URL API performance issue

3 participants