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

Commit

Permalink
fix: de/normalise all file separators in a string
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Shesekino committed May 26, 2019
1 parent 8129211 commit 5c6e90c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/module-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 5c6e90c

Please sign in to comment.