Escape the '.' in '.json' when making static data routes. (#73850)
## Problem
When generating route regular expressions for data routes, some code
paths appear to not escape the `.` in `.json`. This causes routing to be
slightly slower, prevents some optimizations related to static
postfixes, and potentially allows for unintended request paths to be
accepted as value.
## Solution
After much tracing and digging, I found a code path writing regular
expressions directly without escaping. In this case the solution is to
escape the `.` using `\\.` when generating static data routes.
A simple next app was made to exercise this path with a route
`pages/server-time.tsx` that contains a simple `getServerSideProps`.
```tsx
import type { InferGetServerSidePropsType, GetServerSideProps } from 'next'
type TimeDate = {
timestamp: number
}
export const getServerSideProps = (async () => {
return { props: { timestamp: Date.now() } }
}) satisfies GetServerSideProps<TimeDate>
export default function Page({
timestamp,
}: InferGetServerSidePropsType<typeof getServerSideProps>) {
return (
<main>
<p>{new Date(timestamp).toUTCString()}</p>
</main>
)
}
```
Before the change, the generated route regexp was
`"^/_next/data/[build_id]/server-time.json$"`, but after then change it
becomes `"^/_next/data/[build_id]/server-time\\.json$"`
The related tests were updated to expect properly escaped `\\.json$`
endings to the regexps.