Skip to content

Commit

Permalink
De-dupe escape-regex with escape-string-regexp (#10257)
Browse files Browse the repository at this point in the history
* De-dupe escape-regex with escape-string-regex

* Un de-dupe for client-side file
  • Loading branch information
ijjk authored and Timer committed Jan 24, 2020
1 parent 5bcd33f commit 8579888
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions packages/next/package.json
Expand Up @@ -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",
Expand Down
3 changes: 1 addition & 2 deletions test/integration/custom-routes/test/index.test.js
Expand Up @@ -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,
Expand All @@ -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')
Expand Down
5 changes: 3 additions & 2 deletions test/integration/prerender/test/index.test.js
Expand Up @@ -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,
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 8579888

Please sign in to comment.