Skip to content

Commit 6d58fe4

Browse files
committed
fixup! url: reduce pathToFileURL cpp calls
1 parent e906e2b commit 6d58fe4

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

lib/internal/url.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -1414,20 +1414,20 @@ const backslashRegEx = /\\/g;
14141414
const newlineRegEx = /\n/g;
14151415
const carriageReturnRegEx = /\r/g;
14161416
const tabRegEx = /\t/g;
1417-
const questionRegex = /\?/;
1418-
const hashRegex = /#/;
1417+
const questionRegex = /\?/g;
1418+
const hashRegex = /#/g;
14191419

14201420
function encodePathChars(filepath) {
1421-
if (StringPrototypeIncludes(filepath, '%'))
1421+
if (StringPrototypeIndexOf(filepath, '%') !== -1)
14221422
filepath = RegExpPrototypeSymbolReplace(percentRegEx, filepath, '%25');
14231423
// In posix, backslash is a valid character in paths:
1424-
if (!isWindows && StringPrototypeIncludes(filepath, '\\'))
1424+
if (!isWindows && StringPrototypeIndexOf(filepath, '\\') !== -1)
14251425
filepath = RegExpPrototypeSymbolReplace(backslashRegEx, filepath, '%5C');
1426-
if (StringPrototypeIncludes(filepath, '\n'))
1426+
if (StringPrototypeIndexOf(filepath, '\n') !== -1)
14271427
filepath = RegExpPrototypeSymbolReplace(newlineRegEx, filepath, '%0A');
1428-
if (StringPrototypeIncludes(filepath, '\r'))
1428+
if (StringPrototypeIndexOf(filepath, '\r') !== -1)
14291429
filepath = RegExpPrototypeSymbolReplace(carriageReturnRegEx, filepath, '%0D');
1430-
if (StringPrototypeIncludes(filepath, '\t'))
1430+
if (StringPrototypeIndexOf(filepath, '\t') !== -1)
14311431
filepath = RegExpPrototypeSymbolReplace(tabRegEx, filepath, '%09');
14321432
return filepath;
14331433
}
@@ -1473,9 +1473,9 @@ function pathToFileURL(filepath) {
14731473
// Therefore, encoding is required to eliminate parsing them in different states.
14741474
// This is done as an optimization to not creating a URL instance and
14751475
// later triggering pathname setter, which impacts performance
1476-
if (StringPrototypeIncludes(resolved, '?'))
1476+
if (StringPrototypeIndexOf(resolved, '?') !== -1)
14771477
resolved = RegExpPrototypeSymbolReplace(questionRegex, resolved, '%3F');
1478-
if (StringPrototypeIncludes(resolved, '#'))
1478+
if (StringPrototypeIndexOf(resolved, '#') !== -1)
14791479
resolved = RegExpPrototypeSymbolReplace(hashRegex, resolved, '%23');
14801480
return new URL(`file://${resolved}`);
14811481
}

0 commit comments

Comments
 (0)