From dc353bebaff1ffccaeae5bebd7664aba2c0b68ef Mon Sep 17 00:00:00 2001 From: Ronan Jouchet Date: Sat, 16 Jan 2021 08:35:31 -0500 Subject: [PATCH] More filename & appname sanitization --- src/build/prepareElectronApp.ts | 5 ++++- src/utils/sanitizeFilename.ts | 11 +++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/build/prepareElectronApp.ts b/src/build/prepareElectronApp.ts index fef9260..3394c47 100644 --- a/src/build/prepareElectronApp.ts +++ b/src/build/prepareElectronApp.ts @@ -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}`; } diff --git a/src/utils/sanitizeFilename.ts b/src/utils/sanitizeFilename.ts index 7023dab..4c0a089 100644 --- a/src/utils/sanitizeFilename.ts +++ b/src/utils/sanitizeFilename.ts @@ -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;