Skip to content

Commit 495c96b

Browse files
authored
Merge pull request #115 from crazy-max/input-comment-opt
util: comment opt for getInputList
2 parents b1e0aee + 9450a45 commit 495c96b

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

__tests__/util.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,18 @@ describe('getInputList', () => {
7373
expect(res).toEqual(['user/app:cache', 'type=local,src=path/to/dir']);
7474
});
7575

76+
it('multiline and ignoring comment correctly', async () => {
77+
setInput('labels', 'foo=bar\nbar=qux#baz');
78+
const res = Util.getInputList('labels');
79+
expect(res).toEqual(['foo=bar', 'bar=qux#baz']);
80+
});
81+
82+
it('multiline with comment', async () => {
83+
setInput('labels', 'foo=bar\nbar=qux#baz');
84+
const res = Util.getInputList('labels', {comment: '#'});
85+
expect(res).toEqual(['foo=bar', 'bar=qux']);
86+
});
87+
7688
it('different new lines and ignoring comma correctly', async () => {
7789
setInput('cache-from', 'user/app:cache\r\ntype=local,src=path/to/dir');
7890
const res = Util.getInputList('cache-from', {ignoreComma: true});

src/util.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {parse} from 'csv-parse/sync';
2121

2222
export interface InputListOpts {
2323
ignoreComma?: boolean;
24+
comment?: string;
2425
quote?: string | boolean | Buffer | null;
2526
}
2627

@@ -36,7 +37,7 @@ export class Util {
3637
const records = parse(items, {
3738
columns: false,
3839
relaxQuotes: true,
39-
comment: '#',
40+
comment: opts?.comment,
4041
relaxColumnCount: true,
4142
skipEmptyLines: true,
4243
quote: opts?.quote

0 commit comments

Comments
 (0)