@@ -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+
15141517const percentRegEx = / % / g;
15151518const backslashRegEx = / \\ / g;
15161519const newlineRegEx = / \n / g;
15171520const carriageReturnRegEx = / \r / g;
15181521const tabRegEx = / \t / g;
15191522const questionRegex = / \? / g;
15201523const hashRegex = / # / g;
1524+ const nullRegex = / \0 $ / ;
15211525
15221526function 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