Skip to content

Commit

Permalink
fix: escaping special characters in the context option
Browse files Browse the repository at this point in the history
  • Loading branch information
cap-Bernardito committed May 16, 2020
1 parent 0aae9b5 commit 0e62695
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 13 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
},
"dependencies": {
"cacache": "^15.0.3",
"fast-glob": "^3.2.2",
"find-cache-dir": "^3.3.1",
"glob-parent": "^5.1.1",
"globby": "^11.0.0",
Expand Down
9 changes: 2 additions & 7 deletions src/utils/createPatternGlob.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@ import path from 'path';

import normalizePath from 'normalize-path';
import globParent from 'glob-parent';
import fastGlob from 'fast-glob';

function getAbsoluteContext(context) {
const result = normalizePath(path.resolve(context));

return result.replace(
// eslint-disable-next-line no-useless-escape
/[\*|\?|\!|\||\@|\+|\(|\)|\[|\]|\{|\}]/g,
(substring) => `\\${substring}`
);
return fastGlob.escapePath(normalizePath(path.resolve(context)));
}

function createPatternGlob(pattern, globalRef) {
Expand Down
2 changes: 1 addition & 1 deletion test/CopyPlugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ describe('CopyPlugin', () => {
it('should exclude path with linux path segment separators', (done) => {
runEmit({
expectedAssetKeys: [
'[!]/hello.txt',
'[(){}[]!+@escaped-test^$]/hello.txt',
'[special?directory]/(special-*file).txt',
'[special?directory]/directoryfile.txt',
'[special?directory]/nested/nestedfile.txt',
Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions test/from-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ describe('from option', () => {
runEmit({
expectedAssetKeys: [
'.file.txt',
'[!]/hello.txt',
'[(){}[]!+@escaped-test^$]/hello.txt',
'[special?directory]/(special-*file).txt',
'[special?directory]/directoryfile.txt',
'[special?directory]/nested/nestedfile.txt',
Expand Down Expand Up @@ -158,7 +158,7 @@ describe('from option', () => {
runEmit({
expectedAssetKeys: [
'.file.txt',
'[!]/hello.txt',
'[(){}[]!+@escaped-test^$]/hello.txt',
'[special?directory]/(special-*file).txt',
'[special?directory]/directoryfile.txt',
'[special?directory]/nested/nestedfile.txt',
Expand Down Expand Up @@ -339,7 +339,7 @@ describe('from option', () => {
it('should move files using globstar', (done) => {
runEmit({
expectedAssetKeys: [
'[!]/hello.txt',
'[(){}[]!+@escaped-test^$]/hello.txt',
'binextension.bin',
'dir (86)/file.txt',
'dir (86)/nesteddir/deepnesteddir/deepnesteddir.txt',
Expand Down Expand Up @@ -367,7 +367,7 @@ describe('from option', () => {
it('should move files using globstar and contains an absolute path', (done) => {
runEmit({
expectedAssetKeys: [
'[!]/hello.txt',
'[(){}[]!+@escaped-test^$]/hello.txt',
'file.txt',
'directory/directoryfile.txt',
'directory/nested/deep-nested/deepnested.txt',
Expand All @@ -392,7 +392,7 @@ describe('from option', () => {
it('should move files in nested directory using globstar', (done) => {
runEmit({
expectedAssetKeys: [
'nested/[!]/hello-31d6cf.txt',
'nested/[(){}[]!+@escaped-test^$]/hello-31d6cf.txt',
'nested/binextension-31d6cf.bin',
'nested/dir (86)/file-31d6cf.txt',
'nested/dir (86)/nesteddir/deepnesteddir/deepnesteddir-31d6cf.txt',
Expand Down

0 comments on commit 0e62695

Please sign in to comment.