Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from Jan 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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