Unverified Commit 4d307716 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Fix issue with escape-string-regexp in IE11 (#32708)

* Fix issue with escape-string-regexp in IE11

* remove escape-string-regexp dep

* Update compiled

* Link to original repo
parent c9c31832
......@@ -5,7 +5,7 @@ import { isMatch } from 'next/dist/compiled/micromatch'
import { promises, writeFileSync } from 'fs'
import { Worker } from '../lib/worker'
import devalue from 'next/dist/compiled/devalue'
import escapeStringRegexp from 'next/dist/compiled/escape-string-regexp'
import { escapeStringRegexp } from '../shared/lib/escape-regexp'
import findUp from 'next/dist/compiled/find-up'
import { nanoid } from 'next/dist/compiled/nanoid/index.cjs'
import { pathToRegexp } from 'next/dist/compiled/path-to-regexp'
......
......@@ -6,7 +6,7 @@ import semver from 'next/dist/compiled/semver'
import { webpack } from 'next/dist/compiled/webpack/webpack'
import type { webpack5 } from 'next/dist/compiled/webpack/webpack'
import path, { join as pathJoin, relative as relativePath } from 'path'
import escapeRegExp from 'next/dist/compiled/escape-string-regexp'
import { escapeStringRegexp } from '../shared/lib/escape-regexp'
import {
DOT_NEXT_ALIAS,
NEXT_PROJECT_ROOT,
......@@ -1694,7 +1694,7 @@ export default async function getBaseWebpackConfig(
webpackConfig = await buildConfiguration(webpackConfig, {
supportedBrowsers,
rootDirectory: dir,
customAppFile: new RegExp(escapeRegExp(path.join(pagesDir, `_app`))),
customAppFile: new RegExp(escapeStringRegexp(path.join(pagesDir, `_app`))),
isDevelopment: dev,
isServer,
webServerRuntime,
......
import devalue from 'next/dist/compiled/devalue'
import escapeRegexp from 'next/dist/compiled/escape-string-regexp'
import { join } from 'path'
import { parse } from 'querystring'
import { webpack } from 'next/dist/compiled/webpack/webpack'
import { API_ROUTE } from '../../../../lib/constants'
import { isDynamicRoute } from '../../../../shared/lib/router/utils'
import { escapeStringRegexp } from '../../../../shared/lib/escape-regexp'
import { __ApiPreviewProps } from '../../../../server/api-utils'
import {
BUILD_MANIFEST,
......@@ -62,7 +62,7 @@ const nextServerlessLoader: webpack.loader.Loader = function () {
)
const routesManifest = join(distDir, ROUTES_MANIFEST).replace(/\\/g, '/')
const escapedBuildId = escapeRegexp(buildId)
const escapedBuildId = escapeStringRegexp(buildId)
const pageIsDynamicRoute = isDynamicRoute(page)
const encodedPreviewProps = devalue(
......
This diff is collapsed.
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
(function(){"use strict";var e={3:function(e){const r=/[|\\{}()[\]^$+*?.-]/g;e.exports=e=>{if(typeof e!=="string"){throw new TypeError("Expected a string")}return e.replace(r,"\\$&")}}};var r={};function __nccwpck_require__(_){var t=r[_];if(t!==undefined){return t.exports}var i=r[_]={exports:{}};var n=true;try{e[_](i,i.exports,__nccwpck_require__);n=false}finally{if(n)delete r[_]}return i.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var _=__nccwpck_require__(3);module.exports=_})();
\ No newline at end of file
{"name":"escape-string-regexp","main":"index.js","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"license":"MIT"}
......@@ -2,7 +2,7 @@ import chalk from 'next/dist/compiled/chalk'
import { parse as parseUrl } from 'url'
import { NextConfig } from '../server/config'
import * as pathToRegexp from 'next/dist/compiled/path-to-regexp'
import escapeStringRegexp from 'next/dist/compiled/escape-string-regexp'
import { escapeStringRegexp } from '../shared/lib/escape-regexp'
import {
PERMANENT_REDIRECT_STATUS,
TEMPORARY_REDIRECT_STATUS,
......
......@@ -194,7 +194,6 @@
"debug": "4.1.1",
"devalue": "2.0.1",
"domain-browser": "4.19.0",
"escape-string-regexp": "2.0.0",
"etag": "1.8.1",
"events": "3.3.0",
"find-cache-dir": "3.3.1",
......
// regexp from https://github.com/sindresorhus/escape-string-regexp
export function escapeStringRegexp(str: string) {
return str.replace(/[|\\{}()[\]^$+*?.-]/g, '\\$&')
}
import escapeRegexp from 'next/dist/compiled/escape-string-regexp'
import { escapeStringRegexp } from './escape-regexp'
import { parse, HTMLElement } from 'next/dist/compiled/node-html-parser'
import { OPTIMIZED_FONT_PROVIDERS } from './constants'
......@@ -216,7 +216,7 @@ function isImgEligible(imgElement: HTMLElement): boolean {
}
function preloadTagAlreadyExists(html: string, href: string) {
const escapedHref = escapeRegexp(href)
const escapedHref = escapeStringRegexp(href)
const regex = new RegExp(`<link[^>]*href[^>]*${escapedHref}`)
return html.match(regex)
}
......
......@@ -4,7 +4,7 @@ import type { NextParsedUrlQuery } from '../../../../server/request-meta'
import type { Params } from '../../../../server/router'
import type { RouteHas } from '../../../../lib/load-custom-routes'
import { compile, pathToRegexp } from 'next/dist/compiled/path-to-regexp'
import escapeStringRegexp from 'next/dist/compiled/escape-string-regexp'
import { escapeStringRegexp } from '../../escape-regexp'
import { parseUrl } from './parse-url'
export function matchHas(
......
......@@ -741,16 +741,6 @@ export async function ncc_devalue(task, opts) {
.ncc({ packageName: 'devalue', externals })
.target('compiled/devalue')
}
externals['escape-string-regexp'] = 'next/dist/compiled/escape-string-regexp'
// eslint-disable-next-line camelcase
export async function ncc_escape_string_regexp(task, opts) {
await task
.source(
opts.src || relative(__dirname, require.resolve('escape-string-regexp'))
)
.ncc({ packageName: 'escape-string-regexp', externals, target: 'es5' })
.target('compiled/escape-string-regexp')
}
// eslint-disable-next-line camelcase
externals['find-cache-dir'] = 'next/dist/compiled/find-cache-dir'
......@@ -1469,7 +1459,6 @@ export async function ncc(task, opts) {
'ncc_cross_spawn',
'ncc_debug',
'ncc_devalue',
'ncc_escape_string_regexp',
'ncc_find_cache_dir',
'ncc_find_up',
'ncc_fresh',
......
......@@ -164,10 +164,6 @@ declare module 'next/dist/compiled/devalue' {
import m from 'devalue'
export = m
}
declare module 'next/dist/compiled/escape-string-regexp' {
import m from 'escape-string-regexp'
export = m
}
declare module 'next/dist/compiled/find-up' {
import m from 'find-up'
export = m
......
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