Skip to content

Commit 096a5b6

Browse files
authored
Merge pull request #481 from mrmlnc/ISSUE-480_brace_expansion
ISSUE-480: remove backslashes from the pattern's base directory
2 parents 665be46 + 93a953a commit 096a5b6

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

src/managers/tasks.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,16 @@ describe('Managers → Task', () => {
179179

180180
assert.deepStrictEqual(actual, expected);
181181
});
182+
183+
it('should remove backslashes from the base directory', () => {
184+
const expected: PatternsGroup = {
185+
"a'b": [String.raw`a\'b/*`],
186+
};
187+
188+
const actual = manager.groupPatternsByBaseDirectory([String.raw`a\'b/*`]);
189+
190+
assert.deepStrictEqual(actual, expected);
191+
});
182192
});
183193

184194
describe('.convertPatternGroupsToTasks', () => {

src/managers/tasks.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,13 @@ export function groupPatternsByBaseDirectory(patterns: Pattern[]): PatternsGroup
104104
const group: PatternsGroup = {};
105105

106106
return patterns.reduce((collection, pattern) => {
107-
const base = utils.pattern.getBaseDirectory(pattern);
107+
let base = utils.pattern.getBaseDirectory(pattern);
108+
109+
/**
110+
* After extracting the basic static part of the pattern, it becomes a path,
111+
* so escaping leads to referencing non-existent paths.
112+
*/
113+
base = utils.path.removeBackslashes(base);
108114

109115
if (base in collection) {
110116
collection[base].push(pattern);

src/utils/path.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ describe('Utils → Path', () => {
8181
});
8282
});
8383

84+
describe('.removeBackslashes', () => {
85+
it('should return path without backslashes', () => {
86+
assert.strictEqual(util.removeBackslashes(String.raw`a\b`), 'ab');
87+
assert.strictEqual(util.removeBackslashes(String.raw`a\\\b`), String.raw`ab`);
88+
});
89+
});
90+
8491
describe('.convertPathToPattern', () => {
8592
it('should return a pattern', () => {
8693
assert.strictEqual(util.convertPathToPattern('.{directory}'), String.raw`.\{directory\}`);

src/utils/path.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ export function removeLeadingDotSegment(entry: string): string {
4242
return entry;
4343
}
4444

45+
export function removeBackslashes(entry: string): string {
46+
return entry.replaceAll('\\', '');
47+
}
48+
4549
export const escape = IS_WINDOWS_PLATFORM ? escapeWindowsPath : escapePosixPath;
4650

4751
export function escapeWindowsPath(pattern: Pattern): Pattern {

0 commit comments

Comments
 (0)