Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fixup! url: reduce pathToFileURL cpp calls
  • Loading branch information
anonrig committed Jul 11, 2023
commit 6d58fe41799e5bb3578e1a7467015a759cc6a597
18 changes: 9 additions & 9 deletions lib/internal/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -1414,20 +1414,20 @@ const backslashRegEx = /\\/g;
const newlineRegEx = /\n/g;
const carriageReturnRegEx = /\r/g;
const tabRegEx = /\t/g;
const questionRegex = /\?/;
const hashRegex = /#/;
const questionRegex = /\?/g;
const hashRegex = /#/g;

function encodePathChars(filepath) {
if (StringPrototypeIncludes(filepath, '%'))
if (StringPrototypeIndexOf(filepath, '%') !== -1)
Comment thread
anonrig marked this conversation as resolved.
filepath = RegExpPrototypeSymbolReplace(percentRegEx, filepath, '%25');
// In posix, backslash is a valid character in paths:
if (!isWindows && StringPrototypeIncludes(filepath, '\\'))
if (!isWindows && StringPrototypeIndexOf(filepath, '\\') !== -1)
filepath = RegExpPrototypeSymbolReplace(backslashRegEx, filepath, '%5C');
if (StringPrototypeIncludes(filepath, '\n'))
if (StringPrototypeIndexOf(filepath, '\n') !== -1)
filepath = RegExpPrototypeSymbolReplace(newlineRegEx, filepath, '%0A');
Comment thread
anonrig marked this conversation as resolved.
if (StringPrototypeIncludes(filepath, '\r'))
if (StringPrototypeIndexOf(filepath, '\r') !== -1)
filepath = RegExpPrototypeSymbolReplace(carriageReturnRegEx, filepath, '%0D');
if (StringPrototypeIncludes(filepath, '\t'))
if (StringPrototypeIndexOf(filepath, '\t') !== -1)
filepath = RegExpPrototypeSymbolReplace(tabRegEx, filepath, '%09');
return filepath;
}
Expand Down Expand Up @@ -1473,9 +1473,9 @@ function pathToFileurl("https://github.com/nodejs/node/pull/48709/commits/filepath") {
// Therefore, encoding is required to eliminate parsing them in different states.
// This is done as an optimization to not creating a URL instance and
// later triggering pathname setter, which impacts performance
if (StringPrototypeIncludes(resolved, '?'))
if (StringPrototypeIndexOf(resolved, '?') !== -1)
resolved = RegExpPrototypeSymbolReplace(questionRegex, resolved, '%3F');
Comment thread
anonrig marked this conversation as resolved.
if (StringPrototypeIncludes(resolved, '#'))
if (StringPrototypeIndexOf(resolved, '#') !== -1)
resolved = RegExpPrototypeSymbolReplace(hashRegex, resolved, '%23');
Comment thread
anonrig marked this conversation as resolved.
return new url("https://github.com/nodejs/node/pull/48709/commits/%60file://$%7Bresolved%7D%60");
Comment thread
anonrig marked this conversation as resolved.
}
Expand Down