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 { ...@@ -8,6 +8,7 @@ import {
} from '../../../next-server/lib/constants' } from '../../../next-server/lib/constants'
import { isDynamicRoute } from '../../../next-server/lib/router/utils' import { isDynamicRoute } from '../../../next-server/lib/router/utils'
import { API_ROUTE } from '../../../lib/constants' import { API_ROUTE } from '../../../lib/constants'
import escapeRegexp from 'escape-string-regexp'
export type ServerlessLoaderQuery = { export type ServerlessLoaderQuery = {
page: string page: string
...@@ -46,7 +47,7 @@ const nextServerlessLoader: loader.Loader = function() { ...@@ -46,7 +47,7 @@ const nextServerlessLoader: loader.Loader = function() {
) )
const routesManifest = join(distDir, ROUTES_MANIFEST).replace(/\\/g, '/') const routesManifest = join(distDir, ROUTES_MANIFEST).replace(/\\/g, '/')
const escapedBuildId = buildId.replace(/[|\\{}()[\]^$+*?.-]/g, '\\$&') const escapedBuildId = escapeRegexp(buildId)
const pageIsDynamicRoute = isDynamicRoute(page) const pageIsDynamicRoute = isDynamicRoute(page)
const dynamicRouteImports = pageIsDynamicRoute const dynamicRouteImports = pageIsDynamicRoute
......
...@@ -92,6 +92,7 @@ ...@@ -92,6 +92,7 @@
"css-loader": "3.3.0", "css-loader": "3.3.0",
"cssnano-simple": "1.0.0", "cssnano-simple": "1.0.0",
"devalue": "2.0.1", "devalue": "2.0.1",
"escape-string-regexp": "2.0.0",
"etag": "1.8.1", "etag": "1.8.1",
"file-loader": "4.2.0", "file-loader": "4.2.0",
"find-up": "4.0.0", "find-up": "4.0.0",
......
...@@ -6,6 +6,7 @@ import fs from 'fs-extra' ...@@ -6,6 +6,7 @@ import fs from 'fs-extra'
import { join } from 'path' import { join } from 'path'
import cheerio from 'cheerio' import cheerio from 'cheerio'
import webdriver from 'next-webdriver' import webdriver from 'next-webdriver'
import escapeRegex from 'escape-string-regexp'
import { import {
launchApp, launchApp,
killApp, killApp,
...@@ -29,8 +30,6 @@ let stdout = '' ...@@ -29,8 +30,6 @@ let stdout = ''
let appPort let appPort
let app let app
const escapeRegex = str => str.replace(/[|\\{}()[\]^$+*?.-]/g, '\\$&')
const runTests = (isDev = false) => { const runTests = (isDev = false) => {
it('should handle one-to-one rewrite successfully', async () => { it('should handle one-to-one rewrite successfully', async () => {
const html = await renderViaHTTP(appPort, '/first') const html = await renderViaHTTP(appPort, '/first')
......
...@@ -2,8 +2,9 @@ ...@@ -2,8 +2,9 @@
/* global jasmine */ /* global jasmine */
import fs from 'fs-extra' import fs from 'fs-extra'
import { join } from 'path' import { join } from 'path'
import webdriver from 'next-webdriver'
import cheerio from 'cheerio' import cheerio from 'cheerio'
import webdriver from 'next-webdriver'
import escapeRegex from 'escape-string-regexp'
import { import {
renderViaHTTP, renderViaHTTP,
fetchViaHTTP, fetchViaHTTP,
...@@ -410,7 +411,7 @@ const runTests = (dev = false) => { ...@@ -410,7 +411,7 @@ const runTests = (dev = false) => {
const manifest = JSON.parse( const manifest = JSON.parse(
await fs.readFile(join(appDir, '.next/prerender-manifest.json'), 'utf8') 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 => { Object.keys(manifest.dynamicRoutes).forEach(key => {
const item = manifest.dynamicRoutes[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