From c0fe2e80ff2f4ed8921e141046022273c82a3ff8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Fri, 20 Jul 2018 16:55:25 +0200 Subject: [PATCH] Anonymise one more edge case --- src/helpers/anonymizer.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/helpers/anonymizer.js b/src/helpers/anonymizer.js index f24e45d4..c0602449 100644 --- a/src/helpers/anonymizer.js +++ b/src/helpers/anonymizer.js @@ -11,9 +11,25 @@ const configDir = (() => { const cwd = typeof process === 'object' ? process.cwd() || '.' : '__NOTHING_TO_REPLACE__' +// all the paths the app will use. we replace them to anonymize +const basePaths = { + $USER_DATA: configDir, + '.': cwd, +} + function filepathReplace(path: string) { - if (!cwd) return path - return path.replace(cwd, '.').replace(configDir, '$USER_DATA') + if (!path) return path + const replaced = Object.keys(basePaths).reduce((path, name) => { + const p = basePaths[name] + return replaced + .replace(p, name) // normal replace of the path + .replace(encodeURI(p.replace(/\\/g, '/')), name) // replace of the URI version of the path (that are in file:///) + }, path) + if (replaced.length !== path.length) { + // we need to continue until there is no more occurences + return filepathReplace(replaced) + } + return replaced } function filepathRecursiveReplacer(obj: mixed, seen: Array<*>) {