Skip to content

Commit cec1a11

Browse files
Copilotchenrui333
andauthored
fix(util): support brace expansion globs containing commas in parseInputFiles (#672)
* Initial plan * fix(util): support brace expansion globs containing commas in parseInputFiles Co-authored-by: chenrui333 <[email protected]> * test(util): add comprehensive edge case coverage for brace expansion parsing Co-authored-by: chenrui333 <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: chenrui333 <[email protected]>
1 parent aec2ec5 commit cec1a11

File tree

3 files changed

+77
-9
lines changed

3 files changed

+77
-9
lines changed

__tests__/util.test.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ describe('util', () => {
3939
'loom',
4040
]);
4141
});
42+
it('handles globs with brace groups containing commas', () => {
43+
assert.deepStrictEqual(parseInputFiles('./**/*.{exe,deb,tar.gz}\nfoo,bar'), [
44+
'./**/*.{exe,deb,tar.gz}',
45+
'foo',
46+
'bar',
47+
]);
48+
});
49+
it('handles single-line brace pattern correctly', () => {
50+
assert.deepStrictEqual(parseInputFiles('./**/*.{exe,deb,tar.gz}'), [
51+
'./**/*.{exe,deb,tar.gz}',
52+
]);
53+
});
4254
});
4355
describe('releaseBody', () => {
4456
it('uses input body', () => {
@@ -432,3 +444,36 @@ describe('util', () => {
432444
});
433445
});
434446
});
447+
448+
describe('parseInputFiles edge cases', () => {
449+
it('handles multiple brace groups on same line', () => {
450+
assert.deepStrictEqual(parseInputFiles('./**/*.{exe,deb},./dist/**/*.{zip,tar.gz}'), [
451+
'./**/*.{exe,deb}',
452+
'./dist/**/*.{zip,tar.gz}',
453+
]);
454+
});
455+
456+
it('handles nested braces', () => {
457+
assert.deepStrictEqual(parseInputFiles('path/{a,{b,c}}/file.txt'), ['path/{a,{b,c}}/file.txt']);
458+
});
459+
460+
it('handles empty comma-separated values', () => {
461+
assert.deepStrictEqual(parseInputFiles('foo,,bar'), ['foo', 'bar']);
462+
});
463+
464+
it('handles commas with spaces around braces', () => {
465+
assert.deepStrictEqual(parseInputFiles(' ./**/*.{exe,deb} , file.txt '), [
466+
'./**/*.{exe,deb}',
467+
'file.txt',
468+
]);
469+
});
470+
471+
it('handles mixed newlines and commas with braces', () => {
472+
assert.deepStrictEqual(parseInputFiles('file1.txt\n./**/*.{exe,deb},file2.txt\nfile3.txt'), [
473+
'file1.txt',
474+
'./**/*.{exe,deb}',
475+
'file2.txt',
476+
'file3.txt',
477+
]);
478+
});
479+
});

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/util.ts

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,38 @@ export const releaseBody = (config: Config): string | undefined => {
4343

4444
type Env = { [key: string]: string | undefined };
4545

46+
const smartSplit = (input: string): string[] => {
47+
const result: string[] = [];
48+
let current = '';
49+
let braceDepth = 0;
50+
51+
for (const ch of input) {
52+
if (ch === '{') {
53+
braceDepth++;
54+
}
55+
if (ch === '}') {
56+
braceDepth--;
57+
}
58+
if (ch === ',' && braceDepth === 0) {
59+
if (current.trim()) {
60+
result.push(current.trim());
61+
}
62+
current = '';
63+
} else {
64+
current += ch;
65+
}
66+
}
67+
if (current.trim()) {
68+
result.push(current.trim());
69+
}
70+
return result;
71+
};
72+
4673
export const parseInputFiles = (files: string): string[] => {
47-
return files.split(/\r?\n/).reduce<string[]>(
48-
(acc, line) =>
49-
acc
50-
.concat(line.split(','))
51-
.filter((pat) => pat)
52-
.map((pat) => pat.trim()),
53-
[],
54-
);
74+
return files
75+
.split(/\r?\n/)
76+
.flatMap((line) => smartSplit(line))
77+
.filter((pat) => pat.trim() !== '');
5578
};
5679

5780
export const parseConfig = (env: Env): Config => {

0 commit comments

Comments
 (0)