Merge pull request #38 from crazy-max/util-quote
Some checks failed
publish / publish (push) Has been cancelled

util: handle quote opt with the same api for input list
This commit is contained in:
CrazyMax
2023-02-18 01:57:40 +01:00
committed by GitHub
2 changed files with 9 additions and 3 deletions

View File

@@ -79,9 +79,15 @@ describe('getInputList', () => {
expect(res).toEqual(['user/app:cache', 'type=local,src=path/to/dir']);
});
it('do not escape surrounding quotes', async () => {
setInput('driver-opts', `"env.no_proxy=localhost,127.0.0.1,.mydomain"`);
const res = Util.getInputList('driver-opts', {ignoreComma: true, quote: false});
expect(res).toEqual(['"env.no_proxy=localhost,127.0.0.1,.mydomain"']);
});
it('escape surrounding quotes', async () => {
setInput('platforms', 'linux/amd64\n"linux/arm64,linux/arm/v7"');
const res = Util.getInputList('platforms', {escapeQuotes: true});
const res = Util.getInputList('platforms');
expect(res).toEqual(['linux/amd64', 'linux/arm64', 'linux/arm/v7']);
});

View File

@@ -19,7 +19,7 @@ import {parse} from 'csv-parse/sync';
export interface InputListOpts {
ignoreComma?: boolean;
escapeQuotes?: boolean;
quote?: string | boolean | Buffer | null;
}
export class Util {
@@ -37,7 +37,7 @@ export class Util {
comment: '#',
relaxColumnCount: true,
skipEmptyLines: true,
quote: opts?.escapeQuotes ?? `"`
quote: opts?.quote
});
for (const record of records as Array<string[]>) {