Revert "perf: improve URL validation performance" (#52818)
> https://github.com/nodejs/node/issues/48816 This was an unsafe change that caused errors to the user due to a bug in Node and a fix will get upstreamed soon but in the meantime we should reverse this. Reverts vercel/next.js#52353
This commit is contained in:
parent
299e830b8f
commit
33385aaded
1 changed files with 1 additions and 16 deletions
|
@ -1,25 +1,10 @@
|
|||
const DUMMY_ORIGIN = 'http://n'
|
||||
const INVALID_URL_MESSAGE = 'Invalid request URL'
|
||||
|
||||
// URL.canParse is supported on Node 19 and 20.
|
||||
// Node 18 backport is pending.
|
||||
// Reference: https://github.com/nodejs/node/pull/48345
|
||||
const supportsCanParse = URL.hasOwnProperty('canParse')
|
||||
|
||||
export function validateURL(url: string | undefined): string {
|
||||
if (url == null) {
|
||||
if (!url) {
|
||||
throw new Error(INVALID_URL_MESSAGE)
|
||||
}
|
||||
|
||||
if (supportsCanParse) {
|
||||
// @ts-ignore
|
||||
if (!URL.canParse(url, DUMMY_ORIGIN)) {
|
||||
throw new Error(INVALID_URL_MESSAGE)
|
||||
}
|
||||
|
||||
return url
|
||||
}
|
||||
|
||||
try {
|
||||
const parsed = new URL(url, DUMMY_ORIGIN)
|
||||
// Avoid origin change by extra slashes in pathname
|
||||
|
|
Loading…
Reference in a new issue