Skip to content

Commit c9cb32a

Browse files
committed
url: encode null character at the end of file path
1 parent 2d1b4a8 commit c9cb32a

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

lib/internal/url.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const {
2626
StringPrototypeIndexOf,
2727
StringPrototypeSlice,
2828
StringPrototypeStartsWith,
29+
StringPrototypeEndsWith,
2930
StringPrototypeToWellFormed,
3031
Symbol,
3132
SymbolIterator,
@@ -1511,13 +1512,16 @@ function fileURLToPath(path, options = kEmptyObject) {
15111512
// - CR: The carriage return character is also stripped out by the `pathname`
15121513
// setter.
15131514
// - TAB: The tab character is also stripped out by the `pathname` setter.
1515+
// - NULL: The null character is stripped out by the `URL` constructor.
1516+
15141517
const percentRegEx = /%/g;
15151518
const backslashRegEx = /\\/g;
15161519
const newlineRegEx = /\n/g;
15171520
const carriageReturnRegEx = /\r/g;
15181521
const tabRegEx = /\t/g;
15191522
const questionRegex = /\?/g;
15201523
const hashRegex = /#/g;
1524+
const nullRegex = /\0$/;
15211525

15221526
function encodePathChars(filepath, options = kEmptyObject) {
15231527
const windows = options?.windows;
@@ -1532,6 +1536,8 @@ function encodePathChars(filepath, options = kEmptyObject) {
15321536
filepath = RegExpPrototypeSymbolReplace(carriageReturnRegEx, filepath, '%0D');
15331537
if (StringPrototypeIndexOf(filepath, '\t') !== -1)
15341538
filepath = RegExpPrototypeSymbolReplace(tabRegEx, filepath, '%09');
1539+
if (StringPrototypeEndsWith(filepath, '\0'))
1540+
filepath = RegExpPrototypeSymbolReplace(nullRegex, filepath, '%00');
15351541
return filepath;
15361542
}
15371543

0 commit comments

Comments
 (0)