mirror of
https://github.com/Llewellynvdm/nativefier.git
synced 2024-09-28 20:29:04 +00:00
parent
46bc71cb63
commit
f4af78018f
@ -6,7 +6,7 @@ import * as dns from 'dns';
|
|||||||
import * as log from 'loglevel';
|
import * as log from 'loglevel';
|
||||||
|
|
||||||
import { buildNativefierApp } from './main';
|
import { buildNativefierApp } from './main';
|
||||||
import { isArgFormatValid } from './helpers/helpers';
|
import { isArgFormatInvalid } from './helpers/helpers';
|
||||||
import { isWindows } from './helpers/helpers';
|
import { isWindows } from './helpers/helpers';
|
||||||
|
|
||||||
// package.json is `require`d to let tsc strip the `src` folder by determining
|
// package.json is `require`d to let tsc strip the `src` folder by determining
|
||||||
@ -69,7 +69,7 @@ function checkInternet(): void {
|
|||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
const sanitizedArgs = [];
|
const sanitizedArgs = [];
|
||||||
process.argv.forEach((arg) => {
|
process.argv.forEach((arg) => {
|
||||||
if (isArgFormatValid(arg) === false) {
|
if (isArgFormatInvalid(arg)) {
|
||||||
log.error(
|
log.error(
|
||||||
`Invalid argument passed: ${arg} .\nNativefier supports short options (like "-n") and long options (like "--name"), all lowercase. Run "nativefier --help" for help.\nAborting`,
|
`Invalid argument passed: ${arg} .\nNativefier supports short options (like "-n") and long options (like "--name"), all lowercase. Run "nativefier --help" for help.\nAborting`,
|
||||||
);
|
);
|
||||||
|
@ -1,39 +1,31 @@
|
|||||||
import { isArgFormatValid } from './helpers';
|
import { isArgFormatInvalid } from './helpers';
|
||||||
|
|
||||||
describe('isArgFormatValid', () => {
|
describe('isArgFormatInvalid', () => {
|
||||||
test('is true for short arguments', () => {
|
test('is false for correct short args', () => {
|
||||||
expect(isArgFormatValid('-t')).toBe(true);
|
expect(isArgFormatInvalid('-t')).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('is false for improperly formatted short arguments', () => {
|
test('is true for improperly double-dashed short args', () => {
|
||||||
expect(isArgFormatValid('--t')).toBe(false);
|
expect(isArgFormatInvalid('--t')).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('is true for long arguments', () => {
|
test('is false for correct long args', () => {
|
||||||
expect(isArgFormatValid('--test')).toBe(true);
|
expect(isArgFormatInvalid('--test')).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('is false for improperly formatted long arguments', () => {
|
test('is true for improperly triple-dashed long args', () => {
|
||||||
expect(isArgFormatValid('---test')).toBe(false);
|
expect(isArgFormatInvalid('---test')).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('is false for improperly formatted long arguments', () => {
|
test('is true for improperly single-dashed long args', () => {
|
||||||
expect(isArgFormatValid('-test')).toBe(false);
|
expect(isArgFormatInvalid('-test')).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('is true for long arguments with dashes', () => {
|
test('is false for correct long args with dashes', () => {
|
||||||
expect(isArgFormatValid('--test-run')).toBe(true);
|
expect(isArgFormatInvalid('--test-run')).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('is false for improperly formatted long arguments with dashes', () => {
|
test('is false for correct long args with many dashes', () => {
|
||||||
expect(isArgFormatValid('--test--run')).toBe(false);
|
expect(isArgFormatInvalid('--test-run-with-many-dashes')).toBe(false);
|
||||||
});
|
|
||||||
|
|
||||||
test('is true for long arguments with many dashes', () => {
|
|
||||||
expect(isArgFormatValid('--test-run-with-many-dashes')).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('is false for improperly formatted excessively long arguments', () => {
|
|
||||||
expect(isArgFormatValid('--test--run--with--many--dashes')).toBe(false);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -140,9 +140,13 @@ export function getAllowedIconFormats(platform: string): string[] {
|
|||||||
return formats;
|
return formats;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isArgFormatValid(arg: string): boolean {
|
/**
|
||||||
|
* Refuse args like '--n' or '-name', we accept either short '-n' or long '--name'
|
||||||
|
*/
|
||||||
|
export function isArgFormatInvalid(arg: string): boolean {
|
||||||
return (
|
return (
|
||||||
/^-[a-z]$/i.exec(arg) !== null ||
|
arg.startsWith('---') ||
|
||||||
/^--[a-z]{2,}(-[a-z]{2,})*$/i.exec(arg) !== null
|
/^--[a-z]$/i.exec(arg) !== null ||
|
||||||
|
/^-[a-z]{2,}$/i.exec(arg) !== null
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user