File tree Expand file tree Collapse file tree 2 files changed +12
-6
lines changed Expand file tree Collapse file tree 2 files changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -80,7 +80,6 @@ const path = require('path');
80
80
81
81
const {
82
82
validateFunction,
83
- validateString,
84
83
} = require ( 'internal/validators' ) ;
85
84
86
85
const querystring = require ( 'querystring' ) ;
@@ -1444,22 +1443,20 @@ function encodePathChars(filepath) {
1444
1443
}
1445
1444
1446
1445
function pathToFileURL ( filepath ) {
1447
- validateString ( filepath , 'path' ) ;
1448
-
1449
1446
if ( isWindows && StringPrototypeStartsWith ( filepath , '\\\\' ) ) {
1450
1447
const outURL = new URL ( 'file://' ) ;
1451
1448
// UNC path format: \\server\share\resource
1452
1449
const hostnameEndIndex = StringPrototypeIndexOf ( filepath , '\\' , 2 ) ;
1453
1450
if ( hostnameEndIndex === - 1 ) {
1454
1451
throw new ERR_INVALID_ARG_VALUE (
1455
- 'filepath ' ,
1452
+ 'path ' ,
1456
1453
filepath ,
1457
1454
'Missing UNC resource path' ,
1458
1455
) ;
1459
1456
}
1460
1457
if ( hostnameEndIndex === 2 ) {
1461
1458
throw new ERR_INVALID_ARG_VALUE (
1462
- 'filepath ' ,
1459
+ 'path ' ,
1463
1460
filepath ,
1464
1461
'Empty UNC servername' ,
1465
1462
) ;
Original file line number Diff line number Diff line change @@ -53,7 +53,7 @@ const {
53
53
domainToASCII,
54
54
domainToUnicode,
55
55
fileURLToPath,
56
- pathToFileURL,
56
+ pathToFileURL : _pathToFileURL ,
57
57
urlToHttpOptions,
58
58
unsafeProtocol,
59
59
hostlessProtocol,
@@ -1017,6 +1017,15 @@ Url.prototype.parseHost = function parseHost() {
1017
1017
if ( host ) this . hostname = host ;
1018
1018
} ;
1019
1019
1020
+ // When used internally, we are not obligated to associate TypeError with
1021
+ // this function, so non-strings can be rejected by underlying implementation.
1022
+ // Public API has to validate input and throw appropriate error.
1023
+ function pathToFileURL ( path ) {
1024
+ validateString ( path , 'path' ) ;
1025
+
1026
+ return _pathToFileURL ( path ) ;
1027
+ }
1028
+
1020
1029
module . exports = {
1021
1030
// Original API
1022
1031
Url,
You can’t perform that action at this time.
0 commit comments