Skip to content

Commit

Permalink
fixup! Use RegExpPrototypeSymbolReplace over `StringPrototypeReplac…
Browse files Browse the repository at this point in the history
…eAll`
  • Loading branch information
aduh95 committed Dec 25, 2022
1 parent 80452de commit 2475de3
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/internal/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -1512,12 +1512,17 @@ const carriageReturnRegEx = hardenRegExp(/\r/g);
const tabRegEx = hardenRegExp(/\t/g);

function encodePathChars(filepath) {
filepath = RegExpPrototypeSymbolReplace(percentRegEx, filepath, '%25');
if (StringPrototypeIncludes(filepath, '%'))
filepath = RegExpPrototypeSymbolReplace(percentRegEx, filepath, '%25');
// In posix, backslash is a valid character in paths:
if (!isWindows) filepath = RegExpPrototypeSymbolReplace(backslashRegEx, filepath, '%5C');
filepath = RegExpPrototypeSymbolReplace(newlineRegEx, filepath, '%0A');
filepath = RegExpPrototypeSymbolReplace(carriageReturnRegEx, filepath, '%0D');
filepath = RegExpPrototypeSymbolReplace(tabRegEx, filepath, '%09');
if (!isWindows && StringPrototypeIncludes(filepath, '\\'))
filepath = RegExpPrototypeSymbolReplace(backslashRegEx, filepath, '%5C');
if (StringPrototypeIncludes(filepath, '\n'))
filepath = RegExpPrototypeSymbolReplace(newlineRegEx, filepath, '%0A');
if (StringPrototypeIncludes(filepath, '\r'))
filepath = RegExpPrototypeSymbolReplace(carriageReturnRegEx, filepath, '%0D');
if (StringPrototypeIncludes(filepath, '\t'))
filepath = RegExpPrototypeSymbolReplace(tabRegEx, filepath, '%09');
return filepath;
}

Expand Down

0 comments on commit 2475de3

Please sign in to comment.