-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
url: implement parse method for safer URL parsing
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 PR-URL: #52280 Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Daniel Lemire <daniel@lemire.me> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
- Loading branch information
1 parent
fdcde84
commit 9b18df9
Showing
6 changed files
with
268 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// This intentionally does not use resources/urltestdata.json to preserve resources. | ||
[ | ||
{ | ||
"url": undefined, | ||
"base": undefined, | ||
"expected": false | ||
}, | ||
{ | ||
"url": "aaa:b", | ||
"base": undefined, | ||
"expected": true | ||
}, | ||
{ | ||
"url": undefined, | ||
"base": "aaa:b", | ||
"expected": false | ||
}, | ||
{ | ||
"url": "aaa:/b", | ||
"base": undefined, | ||
"expected": true | ||
}, | ||
{ | ||
"url": undefined, | ||
"base": "aaa:/b", | ||
"expected": true | ||
}, | ||
{ | ||
"url": "https://test:test", | ||
"base": undefined, | ||
"expected": false | ||
}, | ||
{ | ||
"url": "a", | ||
"base": "https://b/", | ||
"expected": true | ||
} | ||
].forEach(({ url, base, expected }) => { | ||
test(() => { | ||
if (expected == false) { | ||
assert_equals(URL.parse(url, base), null); | ||
} else { | ||
assert_equals(URL.parse(url, base).href, new URL(url, base).href); | ||
} | ||
}, `URL.parse(${url}, ${base})`); | ||
}); | ||
|
||
test(() => { | ||
assert_not_equals(URL.parse("https://example/"), URL.parse("https://example/")); | ||
}, `URL.parse() should return a unique object`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters