node-mocks-http icon indicating copy to clipboard operation
node-mocks-http copied to clipboard

Replace parseurl with WHATWG URL API

Open Saturate opened this issue 11 months ago • 6 comments

More information here:

https://github.com/e18e/ecosystem-issues/issues/160

Saturate avatar Feb 17 '25 11:02 Saturate

Stale pull request message

github-actions[bot] avatar Apr 21 '25 01:04 github-actions[bot]

Stale pull request message

github-actions[bot] avatar Jun 27 '25 01:06 github-actions[bot]

Stale pull request message

Hmm, ok? :)

Saturate avatar Jun 27 '25 06:06 Saturate

Stale pull request message

github-actions[bot] avatar Sep 14 '25 01:09 github-actions[bot]

Do you need something from me to make this PR easier to close?

Saturate avatar Sep 15 '25 08:09 Saturate

Hi @Saturate

Copilot actually caught a real issue here.

  • this isn’t a URL, it’s a request object, so you should use new URL(this.url).

  • Also, this.url might not always be an absolute URL. parseurl handled relative ones fine, but the URL constructor doesn’t. Adding a base URL (like Copilot suggested) will make sure relative URLs work correctly and avoid potential problems.

Example:

const req = {
    url: '/some/path?name=foo',
}

console.log(parse(req).pathname); // Output: '/some/path'
console.log(new URL(req.url).pathname); // TypeError: Invalid URL

eugef avatar Sep 16 '25 11:09 eugef