-
Notifications
You must be signed in to change notification settings - Fork 27.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Relax encoding on dynamic prerendered routes (#14717)
It should be enough to encode the characters that `path-to-regexp` uses as path delimiters (`/#?`). Fixes #14691
- Loading branch information
Showing
7 changed files
with
222 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
4 changes: 4 additions & 0 deletions
4
packages/next/next-server/lib/router/utils/escape-path-delimiters.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,4 @@ | ||
// escape delimiters used by path-to-regexp | ||
export default function escapePathDelimiters(segment: string): string { | ||
return segment.replace(/[/#?]/g, (char: string) => encodeURIComponent(char)) | ||
} |
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,27 @@ | ||
import Link from 'next/link' | ||
|
||
export async function getStaticProps({ params: { slug } }) { | ||
return { | ||
props: { slug }, | ||
} | ||
} | ||
|
||
export async function getStaticPaths() { | ||
return { | ||
paths: [{ params: { slug: '[first]' } }, '/dynamic/[second]'], | ||
fallback: false, | ||
} | ||
} | ||
|
||
export default ({ slug }) => { | ||
// Important to not check for `slug` existence (testing that build does not | ||
// render fallback version and error) | ||
return ( | ||
<> | ||
<p id="param">Hi {slug}!</p>{' '} | ||
<Link href="/"> | ||
<a id="home">to home</a> | ||
</Link> | ||
</> | ||
) | ||
} |
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