Fix arg validation regression in #1080 with --{x,y} (fix #1084)

This commit is contained in:
Ronan Jouchet 2020-12-07 16:50:59 -05:00
parent 412b724292
commit 7fd0c748ba
2 changed files with 9 additions and 3 deletions

View File

@ -9,6 +9,11 @@ describe('isArgFormatInvalid', () => {
expect(isArgFormatInvalid('--t')).toBe(true);
});
test('is false for --x and --y (backwards compat, we should have made these short, oh well)', () => {
expect(isArgFormatInvalid('--x')).toBe(false);
expect(isArgFormatInvalid('--y')).toBe(false);
});
test('is false for correct long args', () => {
expect(isArgFormatInvalid('--test')).toBe(false);
});

View File

@ -145,8 +145,9 @@ export function getAllowedIconFormats(platform: string): string[] {
*/
export function isArgFormatInvalid(arg: string): boolean {
return (
arg.startsWith('---') ||
/^--[a-z]$/i.exec(arg) !== null ||
/^-[a-z]{2,}$/i.exec(arg) !== null
(arg.startsWith('---') ||
/^--[a-z]$/i.exec(arg) !== null ||
/^-[a-z]{2,}$/i.exec(arg) !== null) &&
!['--x', '--y'].includes(arg) // exception for long args --{x,y}
);
}