-
Notifications
You must be signed in to change notification settings - Fork 29.1k
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
url: implement parse method for safer URL parsing #52280
Conversation
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
Review requested:
|
Can you add a test 🚀 |
And run |
thanks, sure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
@nodejs/url @nodejs/web-standards any feedback on this? |
There was a problem hiding this 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.
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 |
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