1
0
mirror of https://github.com/jiahaog/Nativefier synced 2024-06-26 07:38:59 +02:00
Nativefier/src/utils/sanitizeFilename.ts
Tedward747 83dce91c47
Strip LRM and RLM in Linux names (fix #1361, PR #1365)
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.
2022-03-20 23:27:57 -04:00

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;
}