From d8d84eee18800f60e477e6ad6fb35c14f054f7f9 Mon Sep 17 00:00:00 2001 From: Sergey Golovin Date: Tue, 13 Feb 2018 14:49:53 +0300 Subject: [PATCH] fs: replace magic numbers by named constants PR-URL: https://github.com/nodejs/node/pull/18757 Reviewed-By: Ruben Bridgewater Reviewed-By: Benjamin Gruenbaum Reviewed-By: Richard Lau Reviewed-By: Myles Borins Reviewed-By: James M Snell Reviewed-By: Vladimir de Turckheim --- lib/fs.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/fs.js b/lib/fs.js index 71eace0aef5b0a..e762f90d96a284 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, @@ -1796,7 +1800,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; @@ -1820,7 +1824,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;