diff --git a/packages/next/build/webpack/loaders/next-serverless-loader.ts b/packages/next/build/webpack/loaders/next-serverless-loader.ts index a454ca739ad59e6..634b09a4d927e26 100644 --- a/packages/next/build/webpack/loaders/next-serverless-loader.ts +++ b/packages/next/build/webpack/loaders/next-serverless-loader.ts @@ -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 diff --git a/packages/next/package.json b/packages/next/package.json index 042409932aa3ac8..82e83b697851d37 100644 --- a/packages/next/package.json +++ b/packages/next/package.json @@ -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", diff --git a/test/integration/custom-routes/test/index.test.js b/test/integration/custom-routes/test/index.test.js index 8b249d82e08d392..5b954b48bd91a91 100644 --- a/test/integration/custom-routes/test/index.test.js +++ b/test/integration/custom-routes/test/index.test.js @@ -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') diff --git a/test/integration/prerender/test/index.test.js b/test/integration/prerender/test/index.test.js index 036070238794e92..d1ecf0f574a2510 100644 --- a/test/integration/prerender/test/index.test.js +++ b/test/integration/prerender/test/index.test.js @@ -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]