Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape the '.' in '.json' when making static data routes. #73850

Merged
merged 10 commits into from
Dec 12, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function buildDataRoute(page: string, buildId: string) {
`^${path.posix.join(
'/_next/data',
escapeStringRegexp(buildId),
`${pagePath}.json`
`${pagePath}\\.json`
)}$`
).source
)
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/edge-pages-support/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ describe('edge-render-getserversideprops', () => {
expect(manifest.dataRoutes).toEqual([
{
dataRouteRegex: normalizeRegEx(
`^/_next/data/${escapeStringRegexp(next.buildId)}/index.json$`
`^/_next/data/${escapeStringRegexp(next.buildId)}/index\\.json$`
),
page: '/',
},
Expand Down
34 changes: 17 additions & 17 deletions test/e2e/getserversideprops/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ let next: NextInstance
const expectedManifestRoutes = () => [
{
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/index.json$`
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/index\\.json$`
),
page: '/',
},
{
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/another.json$`
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/another\\.json$`
),
page: '/another',
},
{
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/blog.json$`
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/blog\\.json$`
),
page: '/blog',
},
Expand Down Expand Up @@ -83,44 +83,44 @@ const expectedManifestRoutes = () => [
},
{
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/custom-cache.json$`
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/custom-cache\\.json$`
),
page: '/custom-cache',
},
{
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/default-revalidate.json$`
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/default-revalidate\\.json$`
),
page: '/default-revalidate',
},
{
dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
buildId
)}\\/early-request-end.json$`,
)}\\/early-request-end\\.json$`,
page: '/early-request-end',
},
{
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/enoent.json$`
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/enoent\\.json$`
),
page: '/enoent',
},
{
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/invalid-keys.json$`
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/invalid-keys\\.json$`
),
page: '/invalid-keys',
},
{
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/non-json.json$`
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/non-json\\.json$`
),
page: '/non-json',
},
{
dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
buildId
)}\\/not-found.json$`,
)}\\/not-found\\.json$`,
page: '/not-found',
},
{
Expand All @@ -137,47 +137,47 @@ const expectedManifestRoutes = () => [
},
{
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/promise.json$`
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/promise\\.json$`
),
page: '/promise',
},
{
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/promise\\/mutate-res.json$`
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/promise\\/mutate-res\\.json$`
),
page: '/promise/mutate-res',
},
{
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(
buildId
)}\\/promise\\/mutate-res-no-streaming.json$`
)}\\/promise\\/mutate-res-no-streaming\\.json$`
),
page: '/promise/mutate-res-no-streaming',
},
{
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(
buildId
)}\\/promise\\/mutate-res-props.json$`
)}\\/promise\\/mutate-res-props\\.json$`
),
page: '/promise/mutate-res-props',
},
{
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/refresh.json$`
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/refresh\\.json$`
),
page: '/refresh',
},
{
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/slow.json$`
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/slow\\.json$`
),
page: '/slow',
},
{
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/something.json$`
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/something\\.json$`
),
page: '/something',
},
Expand Down
24 changes: 12 additions & 12 deletions test/e2e/prerender.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1334,15 +1334,15 @@ describe('Prerender', () => {
expect(dataRoutes).toEqual([
{
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(next.buildId)}\\/index.json$`
`^\\/_next\\/data\\/${escapeRegex(next.buildId)}\\/index\\.json$`
),
page: '/',
},
{
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(
next.buildId
)}\\/another.json$`
)}\\/another\\.json$`
),
page: '/another',
},
Expand All @@ -1364,15 +1364,15 @@ describe('Prerender', () => {
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(
next.buildId
)}\\/bad-gssp.json$`
)}\\/bad-gssp\\.json$`
),
page: '/bad-gssp',
},
{
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(
next.buildId
)}\\/bad-ssr.json$`
)}\\/bad-ssr\\.json$`
),
page: '/bad-ssr',
},
Expand Down Expand Up @@ -1414,7 +1414,7 @@ describe('Prerender', () => {
},
{
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(next.buildId)}\\/blog.json$`
`^\\/_next\\/data\\/${escapeRegex(next.buildId)}\\/blog\\.json$`
),
page: '/blog',
},
Expand Down Expand Up @@ -1493,7 +1493,7 @@ describe('Prerender', () => {
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(
next.buildId
)}\\/default-revalidate.json$`
)}\\/default-revalidate\\.json$`
),
page: '/default-revalidate',
},
Expand Down Expand Up @@ -1530,7 +1530,7 @@ describe('Prerender', () => {
// dataRouteRegex: normalizeRegEx(
// `^\\/_next\\/data\\/${escapeRegex(
// next.buildId
// )}\\/index\\/index.json$`
// )}\\/index\\/index\\.json$`
// ),
// page: '/index',
// },
Expand All @@ -1551,13 +1551,13 @@ describe('Prerender', () => {
{
dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
next.buildId
)}\\/large-page-data.json$`,
)}\\/large-page-data\\.json$`,
page: '/large-page-data',
},
{
dataRouteRegex: `^\\/_next\\/data\\/${escapeRegex(
next.buildId
)}\\/large-page-data-ssr.json$`,
)}\\/large-page-data-ssr\\.json$`,
page: '/large-page-data-ssr',
},
{
Expand Down Expand Up @@ -1592,21 +1592,21 @@ describe('Prerender', () => {
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(
next.buildId
)}\\/preview.json$`
)}\\/preview\\.json$`
),
page: '/preview',
},
{
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(
next.buildId
)}\\/something.json$`
)}\\/something\\.json$`
),
page: '/something',
},
{
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(next.buildId)}\\/ssr.json$`
`^\\/_next\\/data\\/${escapeRegex(next.buildId)}\\/ssr\\.json$`
),
page: '/ssr',
},
Expand Down
Loading