Skip to content
This repository was archived by the owner on Jun 2, 2022. It is now read-only.

Commit 5c6e90c

Browse files
committed
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.
1 parent 8129211 commit 5c6e90c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/module-utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ function normalizeScriptPath(scriptPath) {
3939

4040
function normaliseSeparator(pathToNormalise) {
4141
if (path.sep === '\\') {
42-
return pathToNormalise.replace('/', '\\');
42+
return pathToNormalise.replace(/\//g, '\\');
4343
}
4444
return pathToNormalise;
4545
}
4646

4747
function denormaliseSeparator(pathToDenormalise) {
4848
if (path.sep === '\\') {
49-
return pathToDenormalise.replace('\\', '/');
49+
return pathToDenormalise.replace(/\\/g, '/');
5050
}
5151
return pathToDenormalise;
5252
}

0 commit comments

Comments
 (0)