Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

util: comment opt for getInputList #115

Merged
merged 1 commit into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions __tests__/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ describe('getInputList', () => {
expect(res).toEqual(['user/app:cache', 'type=local,src=path/to/dir']);
});

it('multiline and ignoring comment correctly', async () => {
setInput('labels', 'foo=bar\nbar=qux#baz');
const res = Util.getInputList('labels');
expect(res).toEqual(['foo=bar', 'bar=qux#baz']);
});

it('multiline with comment', async () => {
setInput('labels', 'foo=bar\nbar=qux#baz');
const res = Util.getInputList('labels', {comment: '#'});
expect(res).toEqual(['foo=bar', 'bar=qux']);
});

it('different new lines and ignoring comma correctly', async () => {
setInput('cache-from', 'user/app:cache\r\ntype=local,src=path/to/dir');
const res = Util.getInputList('cache-from', {ignoreComma: true});
Expand Down
3 changes: 2 additions & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {parse} from 'csv-parse/sync';

export interface InputListOpts {
ignoreComma?: boolean;
comment?: string;
quote?: string | boolean | Buffer | null;
}

Expand All @@ -36,7 +37,7 @@ export class Util {
const records = parse(items, {
columns: false,
relaxQuotes: true,
comment: '#',
comment: opts?.comment,
relaxColumnCount: true,
skipEmptyLines: true,
quote: opts?.quote
Expand Down