From 3390ab4c3203a3af3d8a02526a45bbc2b4b05fb1 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Wed, 30 Sep 2020 09:51:16 +0200 Subject: [PATCH] update enhanced-resolve and loader-runner for fragment escaping support add fragment escaping support fixes #11555 --- lib/util/identifier.js | 6 ++--- package.json | 5 ++-- test/cases/resolving/issue-11555/index.js | 29 +++++++++++++++++++++++ types.d.ts | 4 ++++ yarn.lock | 18 +++++++------- 5 files changed, 48 insertions(+), 14 deletions(-) create mode 100644 test/cases/resolving/issue-11555/index.js diff --git a/lib/util/identifier.js b/lib/util/identifier.js index 6146604d6..8482a3f7a 100644 --- a/lib/util/identifier.js +++ b/lib/util/identifier.js @@ -244,7 +244,7 @@ const _absolutify = (context, request) => { const absolutify = makeCacheable(_absolutify); exports.absolutify = absolutify; -const PATH_QUERY_FRAGMENT_REGEXP = /^([^?#]*)(\?[^#]*)?(#.*)?$/; +const PATH_QUERY_FRAGMENT_REGEXP = /^((?:\0.|[^?#\0])*)(\?(?:\0.|[^#\0])*)?(#.*)?$/; /** @typedef {{ resource: string, path: string, query: string, fragment: string }} ParsedResource */ @@ -256,8 +256,8 @@ const _parseResource = str => { const match = PATH_QUERY_FRAGMENT_REGEXP.exec(str); return { resource: str, - path: match[1], - query: match[2] || "", + path: match[1].replace(/\0(.)/g, "$1"), + query: match[2] ? match[2].replace(/\0(.)/g, "$1") : "", fragment: match[3] || "" }; }; diff --git a/package.json b/package.json index 9531ded90..e1c76e700 100644 --- a/package.json +++ b/package.json @@ -14,13 +14,13 @@ "acorn": "^7.4.0", "browserslist": "^4.14.3", "chrome-trace-event": "^1.0.2", - "enhanced-resolve": "^5.1.0", + "enhanced-resolve": "^5.2.0", "eslint-scope": "^5.1.0", "events": "^3.2.0", "glob-to-regexp": "^0.4.1", "graceful-fs": "^4.2.4", "json-parse-better-errors": "^1.0.2", - "loader-runner": "^4.0.0", + "loader-runner": "^4.1.0", "mime-types": "^2.1.27", "neo-async": "^2.6.2", "pkg-dir": "^4.2.0", @@ -50,6 +50,7 @@ "cspell": "^4.0.63", "css-loader": "^3.6.0", "date-fns": "^2.15.0", + "es5-ext": "^0.10.53", "es6-promise-polyfill": "^1.2.0", "eslint": "^6.8.0", "eslint-config-prettier": "^6.11.0", diff --git a/test/cases/resolving/issue-11555/index.js b/test/cases/resolving/issue-11555/index.js new file mode 100644 index 000000000..b1e5ba784 --- /dev/null +++ b/test/cases/resolving/issue-11555/index.js @@ -0,0 +1,29 @@ +it("should be possible to use # in folders", () => { + const eIndexOf = require("es5-ext/array/#/e-index-of"); + expect(eIndexOf).toBeTypeOf("function"); +}); + +it("should be possible to use # in folders (context)", () => { + const x = "e-index-of"; + const eIndexOf = require(`es5-ext/array/#/${x}`); + expect(eIndexOf).toBeTypeOf("function"); +}); + +it("should be possible to use # in folders (context)", () => { + const array = require("es5-ext/array"); + expect(array).toMatchObject({ + "#": expect.objectContaining({ + clear: expect.toBeTypeOf("function") + }) + }); +}); + +it("should be possible escape # in requests", () => { + const eIndexOf = require("es5-ext/array/\0#/e-index-of#fragment"); + expect(eIndexOf).toBeTypeOf("function"); +}); + +it("should be possible dynamically import # in folders", async () => { + const eIndexOf = await import("es5-ext/array/#/first"); + expect(eIndexOf.default).toBeTypeOf("function"); +}); diff --git a/types.d.ts b/types.d.ts index 4ab27b73b..78c02744a 100644 --- a/types.d.ts +++ b/types.d.ts @@ -3366,6 +3366,10 @@ declare interface FileSystem { (arg0: string, arg1: FileSystemCallback): void; (arg0: string, arg1: any, arg2: FileSystemCallback): void; }; + lstat?: { + (arg0: string, arg1: FileSystemCallback): void; + (arg0: string, arg1: any, arg2: FileSystemCallback): void; + }; stat: { (arg0: string, arg1: FileSystemCallback): void; (arg0: string, arg1: any, arg2: FileSystemCallback): void; diff --git a/yarn.lock b/yarn.lock index 400db1cc2..c4549abb8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2333,10 +2333,10 @@ enhanced-resolve@^4.0.0: memory-fs "^0.5.0" tapable "^1.0.0" -enhanced-resolve@^5.1.0: - version "5.1.0" - resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.1.0.tgz#44cbf2242876ae9044dc32f7207c23c0dd3acdc1" - integrity sha512-EM3ZMRrprkvO44dVdDRGI9pNPY1Vkw15lT/cQk1IwlbcI7Tpc3la8y1FQCuilWQ8qvlq+n19abwPBjVLnld21A== +enhanced-resolve@^5.2.0: + version "5.2.0" + resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.2.0.tgz#3db3307a608f236f33aeea79303d32915792cbab" + integrity sha512-NZlGLl8DxmZoq0uqPPtJfsCAir68uR047+Udsh1FH4+5ydGQdMurn/A430A1BtxASVmMEuS7/XiJ5OxJ9apAzQ== dependencies: graceful-fs "^4.2.4" tapable "^2.0.0" @@ -2362,7 +2362,7 @@ error-ex@^1.3.1: dependencies: is-arrayish "^0.2.1" -es5-ext@^0.10.35, es5-ext@^0.10.45, es5-ext@^0.10.46, es5-ext@^0.10.50, es5-ext@~0.10.14, es5-ext@~0.10.2, es5-ext@~0.10.46: +es5-ext@^0.10.35, es5-ext@^0.10.45, es5-ext@^0.10.46, es5-ext@^0.10.50, es5-ext@^0.10.53, es5-ext@~0.10.14, es5-ext@~0.10.2, es5-ext@~0.10.46: version "0.10.53" resolved "https://registry.yarnpkg.com/es5-ext/-/es5-ext-0.10.53.tgz#93c5a3acfdbef275220ad72644ad02ee18368de1" integrity sha512-Xs2Stw6NiNHWypzRTY1MtaG/uJlwCk8kH81920ma8mvN8Xq1gsfhZvpkImLQArw8AHnv8MT2I45J3c0R8slE+Q== @@ -4337,10 +4337,10 @@ listr2@^2.6.0: rxjs "^6.6.2" through "^2.3.8" -loader-runner@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/loader-runner/-/loader-runner-4.0.0.tgz#02abcfd9fe6ff7a5aeb3547464746c4dc6ba333d" - integrity sha512-Rqf48ufrr48gFjnaqss04QesoXB7VenbpFFIV/0yOKGnpbejrVlOPqTsoX42FG5goXM5Ixekcs4DqDzHOX2z7Q== +loader-runner@^4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/loader-runner/-/loader-runner-4.1.0.tgz#f70bc0c29edbabdf2043e7ee73ccc3fe1c96b42d" + integrity sha512-oR4lB4WvwFoC70ocraKhn5nkKSs23t57h9udUgw8o0iH8hMXeEoRuUgfcvgUwAJ1ZpRqBvcou4N2SMvM1DwMrA== loader-utils@^1.0.2, loader-utils@^1.1.0, loader-utils@^1.2.3, loader-utils@^1.4.0: version "1.4.0"