-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
58 additions
and
39 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
24 changes: 24 additions & 0 deletions
24
packages/next/next-server/lib/router/utils/parse-relative-url.ts
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,24 @@ | ||
const DUMMY_BASE = new URL('http://n') | ||
|
||
/** | ||
* Parses path-relative urls (e.g. `/hello/world?foo=bar`). If url isn't path-relative | ||
* (e.g. `./hello`) then at least base must be. | ||
* Absolute urls are rejected. | ||
*/ | ||
export function parseRelativeUrl(url: string, base?: string) { | ||
const resolvedBase = base ? new URL(base, DUMMY_BASE) : DUMMY_BASE | ||
const { pathname, searchParams, search, hash, href, origin } = new URL( | ||
url, | ||
resolvedBase | ||
) | ||
if (origin !== DUMMY_BASE.origin) { | ||
throw new Error('Invalid relative URL') | ||
} | ||
return { | ||
pathname, | ||
searchParams, | ||
search, | ||
hash, | ||
href: href.slice(DUMMY_BASE.origin.length), | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
packages/next/next-server/lib/router/utils/search-params-to-url-query.ts
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