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

Trailing comma handling for "-s" command line paramenter #15615

Merged
merged 1 commit into from Jul 18, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 26 additions & 0 deletions lib/core-server/src/cli/__tests__/utils.test.ts
@@ -0,0 +1,26 @@
import { parseList } from '../utils';

describe('parseList', () => {
test.each`
source | expected
${'item1,item2, item3'} | ${['item1', 'item2', 'item3']}
${'item1 , item2, item3 '} | ${['item1', 'item2', 'item3']}
`(`Items will be trimmed, source "$source" should return $expected`, ({ source, expected }) => {
const result = parseList(source);
expect(result).toEqual(expected);
});

test.each`
source | expected
${'item1,item2, '} | ${['item1', 'item2']}
${'item1, ,item3 '} | ${['item1', 'item3']}
${'item1,,item3 '} | ${['item1', 'item3']}
${'item1,, '} | ${['item1']}
`(
`Empty items will be stripped, source "$source" should return $expected`,
({ source, expected }) => {
const result = parseList(source);
expect(result).toEqual(expected);
}
);
});
5 changes: 4 additions & 1 deletion lib/core-server/src/cli/utils.ts
Expand Up @@ -2,7 +2,10 @@ import deprecate from 'util-deprecate';
import dedent from 'ts-dedent';

export function parseList(str: string): string[] {
return str.split(',');
return str
.split(',')
.map((item) => item.trim())
.filter((item) => item.length > 0);
}

export function getEnvConfig(program: Record<string, any>, configEnv: Record<string, any>): void {
Expand Down