Commit 8579888c authored by JJ Kasper's avatar JJ Kasper Committed by Joe Haddad

De-dupe escape-regex with escape-string-regexp (#10257)

* De-dupe escape-regex with escape-string-regex

* Un de-dupe for client-side file
parent 5bcd33fc
......@@ -8,6 +8,7 @@ import {
} from '../../../next-server/lib/constants'
import { isDynamicRoute } from '../../../next-server/lib/router/utils'
import { API_ROUTE } from '../../../lib/constants'
import escapeRegexp from 'escape-string-regexp'
export type ServerlessLoaderQuery = {
page: string
......@@ -46,7 +47,7 @@ const nextServerlessLoader: loader.Loader = function() {
)
const routesManifest = join(distDir, ROUTES_MANIFEST).replace(/\\/g, '/')
const escapedBuildId = buildId.replace(/[|\\{}()[\]^$+*?.-]/g, '\\$&')
const escapedBuildId = escapeRegexp(buildId)
const pageIsDynamicRoute = isDynamicRoute(page)
const dynamicRouteImports = pageIsDynamicRoute
......
......@@ -92,6 +92,7 @@
"css-loader": "3.3.0",
"cssnano-simple": "1.0.0",
"devalue": "2.0.1",
"escape-string-regexp": "2.0.0",
"etag": "1.8.1",
"file-loader": "4.2.0",
"find-up": "4.0.0",
......
......@@ -6,6 +6,7 @@ import fs from 'fs-extra'
import { join } from 'path'
import cheerio from 'cheerio'
import webdriver from 'next-webdriver'
import escapeRegex from 'escape-string-regexp'
import {
launchApp,
killApp,
......@@ -29,8 +30,6 @@ let stdout = ''
let appPort
let app
const escapeRegex = str => str.replace(/[|\\{}()[\]^$+*?.-]/g, '\\$&')
const runTests = (isDev = false) => {
it('should handle one-to-one rewrite successfully', async () => {
const html = await renderViaHTTP(appPort, '/first')
......
......@@ -2,8 +2,9 @@
/* global jasmine */
import fs from 'fs-extra'
import { join } from 'path'
import webdriver from 'next-webdriver'
import cheerio from 'cheerio'
import webdriver from 'next-webdriver'
import escapeRegex from 'escape-string-regexp'
import {
renderViaHTTP,
fetchViaHTTP,
......@@ -410,7 +411,7 @@ const runTests = (dev = false) => {
const manifest = JSON.parse(
await fs.readFile(join(appDir, '.next/prerender-manifest.json'), 'utf8')
)
const escapedBuildId = buildId.replace(/[|\\{}()[\]^$+*?.-]/g, '\\$&')
const escapedBuildId = escapeRegex(buildId)
Object.keys(manifest.dynamicRoutes).forEach(key => {
const item = manifest.dynamicRoutes[key]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment