From 5c6e90cef54770b55f2c62b1595449432d5f0c9a Mon Sep 17 00:00:00 2001 From: Amir Moualem Date: Sun, 26 May 2019 11:24:59 +0300 Subject: [PATCH] fix: de/normalise all file separators in a string currently our tests fail on Windows because we neglect to normalise/denormalise all path separators. when interacting with the local filesystem, we need to make sure to use the native separator (slash on linux, backslash on windows). our normalising function used `string.prototype.replace(str, str)` which replaces only the first occurrence in a string. this commit fixes it to the `string.prototype.replace(regex, str)` signature which, coupled with a global regex, replaces all occurences. this commit isn't accompanied with a test since an existing test is already broken, and that test passing will be the proof of correctness. --- lib/module-utils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/module-utils.js b/lib/module-utils.js index 416d29e..0a84d18 100644 --- a/lib/module-utils.js +++ b/lib/module-utils.js @@ -39,14 +39,14 @@ function normalizeScriptPath(scriptPath) { function normaliseSeparator(pathToNormalise) { if (path.sep === '\\') { - return pathToNormalise.replace('/', '\\'); + return pathToNormalise.replace(/\//g, '\\'); } return pathToNormalise; } function denormaliseSeparator(pathToDenormalise) { if (path.sep === '\\') { - return pathToDenormalise.replace('\\', '/'); + return pathToDenormalise.replace(/\\/g, '/'); } return pathToDenormalise; }