Skip to content

Commit b050d9f

Browse files
Merge branch 'main' into mk/ef-null-check
2 parents ff3a4d4 + 1af512d commit b050d9f

File tree

6 files changed

+56
-48
lines changed

6 files changed

+56
-48
lines changed

package-lock.json

+42-42
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"@babel/preset-env": "^7.15.8",
5353
"@babel/preset-typescript": "^7.16.0",
5454
"@delucis/if-env": "^1.1.2",
55-
"@netlify/build": "^29.5.1",
55+
"@netlify/build": "^29.5.2",
5656
"@netlify/eslint-config-node": "^7.0.1",
5757
"@testing-library/cypress": "^8.0.1",
5858
"@types/fs-extra": "^9.0.13",

packages/runtime/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
},
3737
"devDependencies": {
3838
"@delucis/if-env": "^1.1.2",
39-
"@netlify/build": "^29.5.1",
39+
"@netlify/build": "^29.5.2",
4040
"@types/fs-extra": "^9.0.13",
4141
"@types/jest": "^27.4.1",
4242
"@types/merge-stream": "^1.1.2",

packages/runtime/src/helpers/config.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import slash from 'slash'
99
import { HANDLER_FUNCTION_NAME, ODB_FUNCTION_NAME } from '../constants'
1010

1111
import type { RoutesManifest } from './types'
12+
import { escapeStringRegexp } from './utils'
1213

1314
const ROUTES_MANIFEST_FILE = 'routes-manifest.json'
1415

@@ -214,7 +215,9 @@ export const generateCustomHeaders = (nextConfig: NextConfig, netlifyHeaders: Ne
214215

215216
if (useLocale) {
216217
const { locales } = i18n
217-
const joinedLocales = locales.join('|')
218+
219+
// escape the locale strings to match the way Next writes the routes-manifest.json file
220+
const joinedLocales = locales.map((locale: string) => escapeStringRegexp(locale)).join('|')
218221

219222
/**
220223
* converts e.g.

packages/runtime/src/helpers/utils.ts

+5
Original file line numberDiff line numberDiff line change
@@ -313,3 +313,8 @@ export const getRemotePatterns = (experimental: ExperimentalConfigWithLegacy, im
313313
}
314314
return []
315315
}
316+
317+
// Taken from next/src/shared/lib/escape-regexp.ts
318+
const reHasRegExp = /[|\\{}()[\]^$+*?.-]/
319+
const reReplaceRegExp = /[|\\{}()[\]^$+*?.-]/g
320+
export const escapeStringRegexp = (str: string) => (reHasRegExp.test(str) ? str.replace(reReplaceRegExp, '\\$&') : str)

test/index.spec.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1606,13 +1606,13 @@ describe('function helpers', () => {
16061606
// Next.js has modified the routesManifest to have the locales in the source.
16071607
const nextConfig = {
16081608
i18n: {
1609-
locales: ['en', 'fr'],
1609+
locales: ['en-US', 'fr'],
16101610
defaultLocale: 'en',
16111611
},
16121612
routesManifest: {
16131613
headers: [
16141614
{
1615-
source: '/:nextInternalLocale(en|fr)/with-locale/:path*',
1615+
source: '/:nextInternalLocale(en\\-US|fr)/with-locale/:path*',
16161616
headers: [
16171617
{
16181618
key: 'X-Unit-Test',
@@ -1635,7 +1635,7 @@ describe('function helpers', () => {
16351635
},
16361636
},
16371637
{
1638-
for: '/en/with-locale/*',
1638+
for: '/en-US/with-locale/*',
16391639
values: {
16401640
'X-Unit-Test': 'true',
16411641
},

0 commit comments

Comments
 (0)