Normalize RegEx source between node versions (#9749)
This commit is contained in:
parent
dc51a705c1
commit
8267c8a6eb
5 changed files with 58 additions and 35 deletions
|
@ -15,6 +15,7 @@ import {
|
|||
renderViaHTTP,
|
||||
getBrowserBodyText,
|
||||
waitFor,
|
||||
normalizeRegEx,
|
||||
} from 'next-test-utils'
|
||||
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2
|
||||
|
@ -163,77 +164,77 @@ const runTests = (isDev = false) => {
|
|||
source: '/docs/router-status/:code',
|
||||
destination: '/docs/v2/network/status-codes#:code',
|
||||
statusCode: 301,
|
||||
regex: '^\\/docs\\/router-status(?:\\/([^\\/]+?))$',
|
||||
regex: normalizeRegEx('^\\/docs\\/router-status(?:\\/([^\\/]+?))$'),
|
||||
regexKeys: ['code'],
|
||||
},
|
||||
{
|
||||
source: '/docs/github',
|
||||
destination: '/docs/v2/advanced/now-for-github',
|
||||
statusCode: 301,
|
||||
regex: '^\\/docs\\/github$',
|
||||
regex: normalizeRegEx('^\\/docs\\/github$'),
|
||||
regexKeys: [],
|
||||
},
|
||||
{
|
||||
source: '/docs/v2/advanced/:all(.*)',
|
||||
destination: '/docs/v2/more/:all',
|
||||
statusCode: 301,
|
||||
regex: '^\\/docs\\/v2\\/advanced(?:\\/(.*))$',
|
||||
regex: normalizeRegEx('^\\/docs\\/v2\\/advanced(?:\\/(.*))$'),
|
||||
regexKeys: ['all'],
|
||||
},
|
||||
{
|
||||
source: '/hello/:id/another',
|
||||
destination: '/blog/:id',
|
||||
statusCode: 307,
|
||||
regex: '^\\/hello(?:\\/([^\\/]+?))\\/another$',
|
||||
regex: normalizeRegEx('^\\/hello(?:\\/([^\\/]+?))\\/another$'),
|
||||
regexKeys: ['id'],
|
||||
},
|
||||
{
|
||||
source: '/redirect1',
|
||||
destination: '/',
|
||||
statusCode: 307,
|
||||
regex: '^\\/redirect1$',
|
||||
regex: normalizeRegEx('^\\/redirect1$'),
|
||||
regexKeys: [],
|
||||
},
|
||||
{
|
||||
source: '/redirect2',
|
||||
destination: '/',
|
||||
statusCode: 301,
|
||||
regex: '^\\/redirect2$',
|
||||
regex: normalizeRegEx('^\\/redirect2$'),
|
||||
regexKeys: [],
|
||||
},
|
||||
{
|
||||
source: '/redirect3',
|
||||
destination: '/another',
|
||||
statusCode: 302,
|
||||
regex: '^\\/redirect3$',
|
||||
regex: normalizeRegEx('^\\/redirect3$'),
|
||||
regexKeys: [],
|
||||
},
|
||||
{
|
||||
source: '/redirect4',
|
||||
destination: '/',
|
||||
statusCode: 308,
|
||||
regex: '^\\/redirect4$',
|
||||
regex: normalizeRegEx('^\\/redirect4$'),
|
||||
regexKeys: [],
|
||||
},
|
||||
{
|
||||
source: '/redir-chain1',
|
||||
destination: '/redir-chain2',
|
||||
statusCode: 301,
|
||||
regex: '^\\/redir-chain1$',
|
||||
regex: normalizeRegEx('^\\/redir-chain1$'),
|
||||
regexKeys: [],
|
||||
},
|
||||
{
|
||||
source: '/redir-chain2',
|
||||
destination: '/redir-chain3',
|
||||
statusCode: 302,
|
||||
regex: '^\\/redir-chain2$',
|
||||
regex: normalizeRegEx('^\\/redir-chain2$'),
|
||||
regexKeys: [],
|
||||
},
|
||||
{
|
||||
source: '/redir-chain3',
|
||||
destination: '/',
|
||||
statusCode: 303,
|
||||
regex: '^\\/redir-chain3$',
|
||||
regex: normalizeRegEx('^\\/redir-chain3$'),
|
||||
regexKeys: [],
|
||||
},
|
||||
],
|
||||
|
@ -241,49 +242,51 @@ const runTests = (isDev = false) => {
|
|||
{
|
||||
source: '/hello-world',
|
||||
destination: '/static/hello.txt',
|
||||
regex: '^\\/hello-world$',
|
||||
regex: normalizeRegEx('^\\/hello-world$'),
|
||||
regexKeys: [],
|
||||
},
|
||||
{
|
||||
source: '/',
|
||||
destination: '/another',
|
||||
regex: '^\\/$',
|
||||
regex: normalizeRegEx('^\\/$'),
|
||||
regexKeys: [],
|
||||
},
|
||||
{
|
||||
source: '/another',
|
||||
destination: '/multi-rewrites',
|
||||
regex: '^\\/another$',
|
||||
regex: normalizeRegEx('^\\/another$'),
|
||||
regexKeys: [],
|
||||
},
|
||||
{
|
||||
source: '/first',
|
||||
destination: '/hello',
|
||||
regex: '^\\/first$',
|
||||
regex: normalizeRegEx('^\\/first$'),
|
||||
regexKeys: [],
|
||||
},
|
||||
{
|
||||
source: '/second',
|
||||
destination: '/hello-again',
|
||||
regex: '^\\/second$',
|
||||
regex: normalizeRegEx('^\\/second$'),
|
||||
regexKeys: [],
|
||||
},
|
||||
{
|
||||
source: '/test/:path',
|
||||
destination: '/:path',
|
||||
regex: '^\\/test(?:\\/([^\\/]+?))$',
|
||||
regex: normalizeRegEx('^\\/test(?:\\/([^\\/]+?))$'),
|
||||
regexKeys: ['path'],
|
||||
},
|
||||
{
|
||||
source: '/test-overwrite/:something/:another',
|
||||
destination: '/params/this-should-be-the-value',
|
||||
regex: '^\\/test-overwrite(?:\\/([^\\/]+?))(?:\\/([^\\/]+?))$',
|
||||
regex: normalizeRegEx(
|
||||
'^\\/test-overwrite(?:\\/([^\\/]+?))(?:\\/([^\\/]+?))$'
|
||||
),
|
||||
regexKeys: ['something', 'another'],
|
||||
},
|
||||
{
|
||||
source: '/params/:something',
|
||||
destination: '/with-params',
|
||||
regex: '^\\/params(?:\\/([^\\/]+?))$',
|
||||
regex: normalizeRegEx('^\\/params(?:\\/([^\\/]+?))$'),
|
||||
regexKeys: ['something'],
|
||||
},
|
||||
],
|
||||
|
|
|
@ -12,6 +12,7 @@ import {
|
|||
waitFor,
|
||||
nextBuild,
|
||||
nextStart,
|
||||
normalizeRegEx,
|
||||
} from 'next-test-utils'
|
||||
import cheerio from 'cheerio'
|
||||
|
||||
|
@ -395,35 +396,39 @@ function runTests(dev) {
|
|||
dynamicRoutes: [
|
||||
{
|
||||
page: '/blog/[name]/comment/[id]',
|
||||
regex: '^\\/blog\\/([^\\/]+?)\\/comment\\/([^\\/]+?)(?:\\/)?$',
|
||||
regex: normalizeRegEx(
|
||||
'^\\/blog\\/([^\\/]+?)\\/comment\\/([^\\/]+?)(?:\\/)?$'
|
||||
),
|
||||
},
|
||||
{
|
||||
page: '/on-mount/[post]',
|
||||
regex: '^\\/on\\-mount\\/([^\\/]+?)(?:\\/)?$',
|
||||
regex: normalizeRegEx('^\\/on\\-mount\\/([^\\/]+?)(?:\\/)?$'),
|
||||
},
|
||||
{
|
||||
page: '/p1/p2/all-ssg/[...rest]',
|
||||
regex: '^\\/p1\\/p2\\/all\\-ssg\\/(.+?)(?:\\/)?$',
|
||||
regex: normalizeRegEx('^\\/p1\\/p2\\/all\\-ssg\\/(.+?)(?:\\/)?$'),
|
||||
},
|
||||
{
|
||||
page: '/p1/p2/all-ssr/[...rest]',
|
||||
regex: '^\\/p1\\/p2\\/all\\-ssr\\/(.+?)(?:\\/)?$',
|
||||
regex: normalizeRegEx('^\\/p1\\/p2\\/all\\-ssr\\/(.+?)(?:\\/)?$'),
|
||||
},
|
||||
{
|
||||
page: '/p1/p2/predefined-ssg/[...rest]',
|
||||
regex: '^\\/p1\\/p2\\/predefined\\-ssg\\/(.+?)(?:\\/)?$',
|
||||
regex: normalizeRegEx(
|
||||
'^\\/p1\\/p2\\/predefined\\-ssg\\/(.+?)(?:\\/)?$'
|
||||
),
|
||||
},
|
||||
{
|
||||
page: '/[name]',
|
||||
regex: '^\\/([^\\/]+?)(?:\\/)?$',
|
||||
regex: normalizeRegEx('^\\/([^\\/]+?)(?:\\/)?$'),
|
||||
},
|
||||
{
|
||||
page: '/[name]/comments',
|
||||
regex: '^\\/([^\\/]+?)\\/comments(?:\\/)?$',
|
||||
regex: normalizeRegEx('^\\/([^\\/]+?)\\/comments(?:\\/)?$'),
|
||||
},
|
||||
{
|
||||
page: '/[name]/[comment]',
|
||||
regex: '^\\/([^\\/]+?)\\/([^\\/]+?)(?:\\/)?$',
|
||||
regex: normalizeRegEx('^\\/([^\\/]+?)\\/([^\\/]+?)(?:\\/)?$'),
|
||||
},
|
||||
],
|
||||
})
|
||||
|
|
|
@ -15,6 +15,7 @@ import {
|
|||
nextStart,
|
||||
stopApp,
|
||||
nextExport,
|
||||
normalizeRegEx,
|
||||
startStaticServer,
|
||||
initNextServerScript,
|
||||
} from 'next-test-utils'
|
||||
|
@ -326,18 +327,28 @@ const runTests = (dev = false) => {
|
|||
expect(manifest.dynamicRoutes).toEqual({
|
||||
'/blog/[post]': {
|
||||
dataRoute: `/_next/data/${buildId}/blog/[post].json`,
|
||||
dataRouteRegex: `^\\/_next\\/data\\/${escapedBuildId}\\/blog\\/([^\\/]+?)\\.json$`,
|
||||
routeRegex: '^\\/blog\\/([^\\/]+?)(?:\\/)?$',
|
||||
dataRouteRegex: normalizeRegEx(
|
||||
`^\\/_next\\/data\\/${escapedBuildId}\\/blog\\/([^\\/]+?)\\.json$`
|
||||
),
|
||||
routeRegex: normalizeRegEx('^\\/blog\\/([^\\/]+?)(?:\\/)?$'),
|
||||
},
|
||||
'/blog/[post]/[comment]': {
|
||||
dataRoute: `/_next/data/${buildId}/blog/[post]/[comment].json`,
|
||||
dataRouteRegex: `^\\/_next\\/data\\/${escapedBuildId}\\/blog\\/([^\\/]+?)\\/([^\\/]+?)\\.json$`,
|
||||
routeRegex: '^\\/blog\\/([^\\/]+?)\\/([^\\/]+?)(?:\\/)?$',
|
||||
dataRouteRegex: normalizeRegEx(
|
||||
`^\\/_next\\/data\\/${escapedBuildId}\\/blog\\/([^\\/]+?)\\/([^\\/]+?)\\.json$`
|
||||
),
|
||||
routeRegex: normalizeRegEx(
|
||||
'^\\/blog\\/([^\\/]+?)\\/([^\\/]+?)(?:\\/)?$'
|
||||
),
|
||||
},
|
||||
'/user/[user]/profile': {
|
||||
dataRoute: `/_next/data/${buildId}/user/[user]/profile.json`,
|
||||
dataRouteRegex: `^\\/_next\\/data\\/${escapedBuildId}\\/user\\/([^\\/]+?)\\/profile\\.json$`,
|
||||
routeRegex: `^\\/user\\/([^\\/]+?)\\/profile(?:\\/)?$`,
|
||||
dataRouteRegex: normalizeRegEx(
|
||||
`^\\/_next\\/data\\/${escapedBuildId}\\/user\\/([^\\/]+?)\\/profile\\.json$`
|
||||
),
|
||||
routeRegex: normalizeRegEx(
|
||||
`^\\/user\\/([^\\/]+?)\\/profile(?:\\/)?$`
|
||||
),
|
||||
},
|
||||
})
|
||||
})
|
||||
|
|
|
@ -399,3 +399,7 @@ export async function getReactErrorOverlayContent(browser) {
|
|||
export function getBrowserBodyText(browser) {
|
||||
return browser.eval('document.getElementsByTagName("body")[0].innerText')
|
||||
}
|
||||
|
||||
export function normalizeRegEx(src) {
|
||||
return new RegExp(src).source
|
||||
}
|
||||
|
|
|
@ -4172,7 +4172,7 @@ browserify-zlib@^0.2.0:
|
|||
dependencies:
|
||||
pako "~1.0.5"
|
||||
|
||||
browserslist@^4.0.0, browserslist@^4.3.6, browserslist@^4.6.0, browserslist@^4.6.3, browserslist@^4.6.4, browserslist@^4.7.3:
|
||||
browserslist@^4.0.0, browserslist@^4.3.6, browserslist@^4.6.0, browserslist@^4.6.3, browserslist@^4.6.4, browserslist@^4.7.1, browserslist@^4.7.3:
|
||||
version "4.8.2"
|
||||
resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.8.2.tgz#b45720ad5fbc8713b7253c20766f701c9a694289"
|
||||
integrity sha512-+M4oeaTplPm/f1pXDw84YohEv7B1i/2Aisei8s4s6k3QsoSHa7i5sz8u/cGQkkatCPxMASKxPualR4wwYgVboA==
|
||||
|
@ -4436,7 +4436,7 @@ caniuse-api@^3.0.0:
|
|||
lodash.memoize "^4.1.2"
|
||||
lodash.uniq "^4.5.0"
|
||||
|
||||
caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000980, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.30001010, caniuse-lite@^1.0.30001015:
|
||||
caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000980, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.30001002, caniuse-lite@^1.0.30001010, caniuse-lite@^1.0.30001015:
|
||||
version "1.0.30001015"
|
||||
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001015.tgz#15a7ddf66aba786a71d99626bc8f2b91c6f0f5f0"
|
||||
integrity sha512-/xL2AbW/XWHNu1gnIrO8UitBGoFthcsDgU9VLK1/dpsoxbaD5LscHozKze05R6WLsBvLhqv78dAPozMFQBYLbQ==
|
||||
|
|
Loading…
Reference in a new issue