Skip to content

Commit

Permalink
url: encode null character at the end of file path
Browse files Browse the repository at this point in the history
  • Loading branch information
EarlyRiser42 committed Jul 27, 2024
1 parent 2d1b4a8 commit c9cb32a
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/internal/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const {
StringPrototypeIndexOf,
StringPrototypeSlice,
StringPrototypeStartsWith,
StringPrototypeEndsWith,

Check failure on line 29 in lib/internal/url.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Out of ASCIIbetical order - StringPrototypeStartsWith >= StringPrototypeEndsWith
StringPrototypeToWellFormed,
Symbol,
SymbolIterator,
Expand Down Expand Up @@ -1511,13 +1512,16 @@ function fileURLToPath(path, options = kEmptyObject) {
// - CR: The carriage return character is also stripped out by the `pathname`
// setter.
// - TAB: The tab character is also stripped out by the `pathname` setter.
// - NULL: The null character is stripped out by the `URL` constructor.

const percentRegEx = /%/g;
const backslashRegEx = /\\/g;
const newlineRegEx = /\n/g;
const carriageReturnRegEx = /\r/g;
const tabRegEx = /\t/g;
const questionRegex = /\?/g;
const hashRegex = /#/g;
const nullRegex = /\0$/;

function encodePathChars(filepath, options = kEmptyObject) {
const windows = options?.windows;
Expand All @@ -1532,6 +1536,8 @@ function encodePathChars(filepath, options = kEmptyObject) {
filepath = RegExpPrototypeSymbolReplace(carriageReturnRegEx, filepath, '%0D');
if (StringPrototypeIndexOf(filepath, '\t') !== -1)
filepath = RegExpPrototypeSymbolReplace(tabRegEx, filepath, '%09');
if (StringPrototypeEndsWith(filepath, '\0'))
filepath = RegExpPrototypeSymbolReplace(nullRegex, filepath, '%00');
return filepath;
}

Expand Down

0 comments on commit c9cb32a

Please sign in to comment.