Skip to content

Commit

Permalink
Merge pull request #15615 from apalumbo/next
Browse files Browse the repository at this point in the history
Trailing comma handling for "-s" command line paramenter
  • Loading branch information
shilman committed Jul 18, 2021
2 parents 3c076a3 + c2f018d commit e87b321
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
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

0 comments on commit e87b321

Please sign in to comment.