From 9450a454a76c5f2876dd4b5a5c17d600a65025c1 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Fri, 9 Jun 2023 14:11:57 +0200 Subject: [PATCH] util: comment opt for getInputList Signed-off-by: CrazyMax --- __tests__/util.test.ts | 12 ++++++++++++ src/util.ts | 3 ++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/__tests__/util.test.ts b/__tests__/util.test.ts index 1dcac75..7f41d0d 100644 --- a/__tests__/util.test.ts +++ b/__tests__/util.test.ts @@ -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}); diff --git a/src/util.ts b/src/util.ts index 7d1052f..d281715 100644 --- a/src/util.ts +++ b/src/util.ts @@ -21,6 +21,7 @@ import {parse} from 'csv-parse/sync'; export interface InputListOpts { ignoreComma?: boolean; + comment?: string; quote?: string | boolean | Buffer | null; } @@ -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