Skip to content

Commit

Permalink
Revert "perf: improve URL validation performance" (#52818)
Browse files Browse the repository at this point in the history
> 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
  • Loading branch information
feedthejim authored Jul 18, 2023
1 parent 299e830 commit 33385aa
Showing 1 changed file with 1 addition and 16 deletions.
17 changes: 1 addition & 16 deletions packages/next/src/server/app-render/validate-url.tsx
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 33385aa

Please sign in to comment.