Skip to content

Commit da9defb

Browse files
committed
squash: make url.pathToFileURL into public wrapper
1 parent cddbbef commit da9defb

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

lib/internal/url.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ const path = require('path');
8080

8181
const {
8282
validateFunction,
83-
validateString,
8483
} = require('internal/validators');
8584

8685
const querystring = require('querystring');
@@ -1444,22 +1443,20 @@ function encodePathChars(filepath) {
14441443
}
14451444

14461445
function pathToFileURL(filepath) {
1447-
validateString(filepath, 'path');
1448-
14491446
if (isWindows && StringPrototypeStartsWith(filepath, '\\\\')) {
14501447
const outURL = new URL('file://');
14511448
// UNC path format: \\server\share\resource
14521449
const hostnameEndIndex = StringPrototypeIndexOf(filepath, '\\', 2);
14531450
if (hostnameEndIndex === -1) {
14541451
throw new ERR_INVALID_ARG_VALUE(
1455-
'filepath',
1452+
'path',
14561453
filepath,
14571454
'Missing UNC resource path',
14581455
);
14591456
}
14601457
if (hostnameEndIndex === 2) {
14611458
throw new ERR_INVALID_ARG_VALUE(
1462-
'filepath',
1459+
'path',
14631460
filepath,
14641461
'Empty UNC servername',
14651462
);

lib/url.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const {
5353
domainToASCII,
5454
domainToUnicode,
5555
fileURLToPath,
56-
pathToFileURL,
56+
pathToFileURL: _pathToFileURL,
5757
urlToHttpOptions,
5858
unsafeProtocol,
5959
hostlessProtocol,
@@ -1017,6 +1017,15 @@ Url.prototype.parseHost = function parseHost() {
10171017
if (host) this.hostname = host;
10181018
};
10191019

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+
10201029
module.exports = {
10211030
// Original API
10221031
Url,

0 commit comments

Comments
 (0)