Skip to content

Commit 0e62695

Browse files
fix: escaping special characters in the context option
1 parent 0aae9b5 commit 0e62695

File tree

5 files changed

+9
-13
lines changed

5 files changed

+9
-13
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
},
4343
"dependencies": {
4444
"cacache": "^15.0.3",
45+
"fast-glob": "^3.2.2",
4546
"find-cache-dir": "^3.3.1",
4647
"glob-parent": "^5.1.1",
4748
"globby": "^11.0.0",

src/utils/createPatternGlob.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,10 @@ import path from 'path';
22

33
import normalizePath from 'normalize-path';
44
import globParent from 'glob-parent';
5+
import fastGlob from 'fast-glob';
56

67
function getAbsoluteContext(context) {
7-
const result = normalizePath(path.resolve(context));
8-
9-
return result.replace(
10-
// eslint-disable-next-line no-useless-escape
11-
/[\*|\?|\!|\||\@|\+|\(|\)|\[|\]|\{|\}]/g,
12-
(substring) => `\\${substring}`
13-
);
8+
return fastGlob.escapePath(normalizePath(path.resolve(context)));
149
}
1510

1611
function createPatternGlob(pattern, globalRef) {

test/CopyPlugin.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ describe('CopyPlugin', () => {
238238
it('should exclude path with linux path segment separators', (done) => {
239239
runEmit({
240240
expectedAssetKeys: [
241-
'[!]/hello.txt',
241+
'[(){}[]!+@escaped-test^$]/hello.txt',
242242
'[special?directory]/(special-*file).txt',
243243
'[special?directory]/directoryfile.txt',
244244
'[special?directory]/nested/nestedfile.txt',
File renamed without changes.

test/from-option.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ describe('from option', () => {
128128
runEmit({
129129
expectedAssetKeys: [
130130
'.file.txt',
131-
'[!]/hello.txt',
131+
'[(){}[]!+@escaped-test^$]/hello.txt',
132132
'[special?directory]/(special-*file).txt',
133133
'[special?directory]/directoryfile.txt',
134134
'[special?directory]/nested/nestedfile.txt',
@@ -158,7 +158,7 @@ describe('from option', () => {
158158
runEmit({
159159
expectedAssetKeys: [
160160
'.file.txt',
161-
'[!]/hello.txt',
161+
'[(){}[]!+@escaped-test^$]/hello.txt',
162162
'[special?directory]/(special-*file).txt',
163163
'[special?directory]/directoryfile.txt',
164164
'[special?directory]/nested/nestedfile.txt',
@@ -339,7 +339,7 @@ describe('from option', () => {
339339
it('should move files using globstar', (done) => {
340340
runEmit({
341341
expectedAssetKeys: [
342-
'[!]/hello.txt',
342+
'[(){}[]!+@escaped-test^$]/hello.txt',
343343
'binextension.bin',
344344
'dir (86)/file.txt',
345345
'dir (86)/nesteddir/deepnesteddir/deepnesteddir.txt',
@@ -367,7 +367,7 @@ describe('from option', () => {
367367
it('should move files using globstar and contains an absolute path', (done) => {
368368
runEmit({
369369
expectedAssetKeys: [
370-
'[!]/hello.txt',
370+
'[(){}[]!+@escaped-test^$]/hello.txt',
371371
'file.txt',
372372
'directory/directoryfile.txt',
373373
'directory/nested/deep-nested/deepnested.txt',
@@ -392,7 +392,7 @@ describe('from option', () => {
392392
it('should move files in nested directory using globstar', (done) => {
393393
runEmit({
394394
expectedAssetKeys: [
395-
'nested/[!]/hello-31d6cf.txt',
395+
'nested/[(){}[]!+@escaped-test^$]/hello-31d6cf.txt',
396396
'nested/binextension-31d6cf.bin',
397397
'nested/dir (86)/file-31d6cf.txt',
398398
'nested/dir (86)/nesteddir/deepnesteddir/deepnesteddir-31d6cf.txt',

0 commit comments

Comments
 (0)