More filename & appname sanitization

This commit is contained in:
Ronan Jouchet 2021-01-16 08:35:31 -05:00
parent 3b28dc46cc
commit dc353bebaf
2 changed files with 11 additions and 5 deletions

View File

@ -105,7 +105,10 @@ function normalizeAppName(appName: string, url: string): string {
const hash = crypto.createHash('md5');
hash.update(url);
const postFixHash = hash.digest('hex').substring(0, 6);
const normalized = appName.toLowerCase().replace(/[\s_]/g, '-');
const normalized = appName
.toLowerCase()
.replace(/[,:.]/g, '')
.replace(/[\s_]/g, '-');
return `${normalized}-nativefier-${postFixHash}`;
}

View File

@ -11,13 +11,16 @@ export function sanitizeFilename(
): string {
let result: string = sanitize(filenameToSanitize);
// remove all non ascii or use default app name
// eslint-disable-next-line no-control-regex
result = result.replace(/[^\x00-\x7F]/g, '') || DEFAULT_APP_NAME;
// remove all non ascii / file-problematic chars, or use default app name
/* eslint-disable no-control-regex */
result =
result.replace(/[^\x00-\x7F]/g, '').replace(/[/,;.\\]/g, '') ||
DEFAULT_APP_NAME;
/* eslint-enable no-control-regex */
// spaces will cause problems with Ubuntu when pinned to the dock
if (platform === 'linux') {
result = result.replace(/ /g, '');
result = result.replace(/\s/g, '');
}
log.debug(`Sanitized filename for ${filenameToSanitize} : ${result}`);
return result;