Skip to content

Commit

Permalink
Merge pull request #481 from mrmlnc/ISSUE-480_brace_expansion
Browse files Browse the repository at this point in the history
ISSUE-480: remove backslashes from the pattern's base directory
  • Loading branch information
mrmlnc authored Jan 17, 2025
2 parents 665be46 + 93a953a commit 096a5b6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/managers/tasks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,16 @@ describe('Managers → Task', () => {

assert.deepStrictEqual(actual, expected);
});

it('should remove backslashes from the base directory', () => {
const expected: PatternsGroup = {
"a'b": [String.raw`a\'b/*`],
};

const actual = manager.groupPatternsByBaseDirectory([String.raw`a\'b/*`]);

assert.deepStrictEqual(actual, expected);
});
});

describe('.convertPatternGroupsToTasks', () => {
Expand Down
8 changes: 7 additions & 1 deletion src/managers/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,13 @@ export function groupPatternsByBaseDirectory(patterns: Pattern[]): PatternsGroup
const group: PatternsGroup = {};

return patterns.reduce((collection, pattern) => {
const base = utils.pattern.getBaseDirectory(pattern);
let base = utils.pattern.getBaseDirectory(pattern);

/**
* After extracting the basic static part of the pattern, it becomes a path,
* so escaping leads to referencing non-existent paths.
*/
base = utils.path.removeBackslashes(base);

if (base in collection) {
collection[base].push(pattern);
Expand Down
7 changes: 7 additions & 0 deletions src/utils/path.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ describe('Utils → Path', () => {
});
});

describe('.removeBackslashes', () => {
it('should return path without backslashes', () => {
assert.strictEqual(util.removeBackslashes(String.raw`a\b`), 'ab');
assert.strictEqual(util.removeBackslashes(String.raw`a\\\b`), String.raw`ab`);
});
});

describe('.convertPathToPattern', () => {
it('should return a pattern', () => {
assert.strictEqual(util.convertPathToPattern('.{directory}'), String.raw`.\{directory\}`);
Expand Down
4 changes: 4 additions & 0 deletions src/utils/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export function removeLeadingDotSegment(entry: string): string {
return entry;
}

export function removeBackslashes(entry: string): string {
return entry.replaceAll('\\', '');
}

export const escape = IS_WINDOWS_PLATFORM ? escapeWindowsPath : escapePosixPath;

export function escapeWindowsPath(pattern: Pattern): Pattern {
Expand Down

0 comments on commit 096a5b6

Please sign in to comment.