Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

url: implement parse method for safer URL parsing #52280

Merged
merged 4 commits into from
Apr 13, 2024

Conversation

thisalihassan
Copy link
Contributor

Implement the static parse method as per the WHATWG URL specification. Unlike the URL constructor, URL.parse does not throw on invalid input, instead returning null. This behavior allows safer parsing of URLs without the need for try-catch blocks around constructor calls. The implementation follows the steps outlined in the WHATWG URL standard, ensuring compatibility and consistency with web platform URL parsing APIs.

Fixes: #52208
Refs: whatwg/url#825

Implement the static parse method as per the WHATWG URL specification.
Unlike the URL constructor, URL.parse does not throw on invalid input,
instead returning null. This behavior allows safer parsing of URLs
without the need for try-catch blocks around constructor calls. The
implementation follows the steps outlined in the WHATWG URL standard,
ensuring compatibility and consistency with web platform URL parsing
APIs.

Fixes: nodejs#52208
Refs: whatwg/url#825
@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/url
  • @nodejs/web-standards

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. whatwg-url Issues and PRs related to the WHATWG URL implementation. labels Mar 30, 2024
@thisalihassan thisalihassan marked this pull request as draft March 30, 2024 19:38
@mertcanaltin
Copy link
Member

Can you add a test 🚀

@panva
Copy link
Member

panva commented Mar 30, 2024

Can you add a test 🚀

And run git node wpt url to update the WPT test suite.

lib/internal/url.js Outdated Show resolved Hide resolved
@thisalihassan
Copy link
Contributor Author

Can you add a test 🚀

And run git node wpt url to update the WPT test suite.

thanks, sure

lib/internal/url.js Show resolved Hide resolved
@thisalihassan thisalihassan marked this pull request as ready for review March 31, 2024 11:29
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@thisalihassan
Copy link
Contributor Author

@nodejs/url @nodejs/web-standards any feedback on this?

Copy link
Member

@lemire lemire left a comment

Choose a reason for hiding this comment

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

I encourage the author of this contribution to consider providing a benchmark. It would be interesting to compare this method with the more conventional one and make sure that, at least, it is no slower. Such a benchmark could be provided as part of a follow-up contribution.

src/node_url.cc Outdated Show resolved Hide resolved
src/node_url.cc Outdated Show resolved Hide resolved
lib/internal/url.js Outdated Show resolved Hide resolved
@thisalihassan
Copy link
Contributor Author

I will be doing a benchmark to compare both approaches afterwards, this is facinating to me which one is faster/slower. but can we request CI on this? @nodejs/url @nodejs/web-standards

@nodejs-github-bot
Copy link
Collaborator

@thisalihassan
Copy link
Contributor Author

image
on node-test-commit-osx tests are failing due to no space left on device

@nodejs/url @nodejs/web-standards

@nodejs-github-bot
Copy link
Collaborator

@anonrig anonrig added the request-ci Add this label to start a Jenkins CI on a PR. label Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-blocked-v20.x PRs that should land on the v20.x-staging branch but are blocked by another PR's pending backport. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. needs-ci PRs that need a full CI run. semver-minor PRs that contain new features and should be released in the next minor version. whatwg-url Issues and PRs related to the WHATWG URL implementation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement URL.parse()