mirror of
https://github.com/Llewellynvdm/nativefier.git
synced 2024-11-11 15:51:06 +00:00
83dce91c47
On Linux (SUSE at least), if `--name` isn't provided and is inferred, the filename is prepended with the control character LRM (https://en.wikipedia.org/wiki/Left-to-right_mark) and I'd assume RLM for anyone who's using that setting. This PR strips those control characters out of the file name.
26 lines
743 B
TypeScript
26 lines
743 B
TypeScript
import * as log from 'loglevel';
|
|
import sanitize = require('sanitize-filename');
|
|
|
|
import { DEFAULT_APP_NAME } from '../constants';
|
|
|
|
export function sanitizeFilename(
|
|
platform: string | undefined,
|
|
filenameToSanitize: string,
|
|
): string {
|
|
let result: string = sanitize(filenameToSanitize);
|
|
|
|
// spaces will cause problems with Ubuntu when pinned to the dock
|
|
if (platform === 'linux') {
|
|
result = result.replace(/[\s\u200e\u200f]/g, '');
|
|
}
|
|
|
|
if (!result || result === '') {
|
|
result = DEFAULT_APP_NAME;
|
|
log.warn(
|
|
'Falling back to default app name as result of filename sanitization. Use flag "--name" to set a name',
|
|
);
|
|
}
|
|
log.debug(`Sanitized filename for ${filenameToSanitize} : ${result}`);
|
|
return result;
|
|
}
|