diff --git a/lib/fs.js b/lib/fs.js index da718f3f334413..51fa5c70e04a20 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -46,6 +46,10 @@ const { assertEncoding, stringToFlags } = internalFS; +const { + CHAR_FORWARD_SLASH, + CHAR_BACKWARD_SLASH, +} = require('internal/constants'); Object.defineProperty(exports, 'constants', { configurable: false, @@ -1814,7 +1818,7 @@ if (isWindows) { } else { splitRoot = function splitRoot(str) { for (var i = 0; i < str.length; ++i) { - if (str.charCodeAt(i) !== 47/*'/'*/) + if (str.charCodeAt(i) !== CHAR_FORWARD_SLASH) return str.slice(0, i); } return str; @@ -1838,7 +1842,9 @@ if (isWindows) { nextPart = function nextPart(p, i) { for (; i < p.length; ++i) { const ch = p.charCodeAt(i); - if (ch === 92/*'\'*/ || ch === 47/*'/'*/) + + // Check for a separator character + if (ch === CHAR_BACKWARD_SLASH || ch === CHAR_FORWARD_SLASH) return i; } return -1;