Skip to content

Commit 33385aa

Browse files
authoredJul 18, 2023
Revert "perf: improve URL validation performance" (#52818)
> nodejs/node#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 #52353
1 parent 299e830 commit 33385aa

File tree

1 file changed

+1
-16
lines changed

1 file changed

+1
-16
lines changed
 

‎packages/next/src/server/app-render/validate-url.tsx

+1-16
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,10 @@
11
const DUMMY_ORIGIN = 'http://n'
22
const INVALID_URL_MESSAGE = 'Invalid request URL'
33

4-
// URL.canParse is supported on Node 19 and 20.
5-
// Node 18 backport is pending.
6-
// Reference: https://github.com/nodejs/node/pull/48345
7-
const supportsCanParse = URL.hasOwnProperty('canParse')
8-
94
export function validateURL(url: string | undefined): string {
10-
if (url == null) {
5+
if (!url) {
116
throw new Error(INVALID_URL_MESSAGE)
127
}
13-
14-
if (supportsCanParse) {
15-
// @ts-ignore
16-
if (!URL.canParse(url, DUMMY_ORIGIN)) {
17-
throw new Error(INVALID_URL_MESSAGE)
18-
}
19-
20-
return url
21-
}
22-
238
try {
249
const parsed = new URL(url, DUMMY_ORIGIN)
2510
// Avoid origin change by extra slashes in pathname

0 commit comments

Comments
 (0)
Please sign in to comment.