Skip to content

Commit 8520e6f

Browse files
leggieroTrott
authored andcommitted
lib: fix urlObject parameter name in url.format
Documentation, error message, and code now use the same argument name. PR-URL: #14031 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent e36917b commit 8520e6f

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

lib/url.js

+13-12
Original file line numberDiff line numberDiff line change
@@ -550,22 +550,23 @@ function autoEscapeStr(rest) {
550550
}
551551

552552
// format a parsed object into a url string
553-
function urlFormat(obj, options) {
553+
function urlFormat(urlObject, options) {
554554
// ensure it's an object, and not a string url.
555-
// If it's an obj, this is a no-op.
556-
// this way, you can call url_format() on strings
555+
// If it's an object, this is a no-op.
556+
// this way, you can call urlParse() on strings
557557
// to clean up potentially wonky urls.
558-
if (typeof obj === 'string') {
559-
obj = urlParse(obj);
560-
} else if (typeof obj !== 'object' || obj === null) {
561-
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'urlObj', 'object', obj);
562-
} else if (!(obj instanceof Url)) {
563-
var format = obj[formatSymbol];
558+
if (typeof urlObject === 'string') {
559+
urlObject = urlParse(urlObject);
560+
} else if (typeof urlObject !== 'object' || urlObject === null) {
561+
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'urlObject',
562+
['object', 'string'], urlObject);
563+
} else if (!(urlObject instanceof Url)) {
564+
var format = urlObject[formatSymbol];
564565
return format ?
565-
format.call(obj, options) :
566-
Url.prototype.format.call(obj);
566+
format.call(urlObject, options) :
567+
Url.prototype.format.call(urlObject);
567568
}
568-
return obj.format();
569+
return urlObject.format();
569570
}
570571

571572
Url.prototype.format = function format() {

test/parallel/test-url-format-invalid-input.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ const throwsObjsAndReportTypes = new Map([
1313
[Symbol('foo'), 'symbol']
1414
]);
1515

16-
for (const [obj, type] of throwsObjsAndReportTypes) {
16+
for (const [urlObject, type] of throwsObjsAndReportTypes) {
1717
const error = common.expectsError({
1818
code: 'ERR_INVALID_ARG_TYPE',
1919
type: TypeError,
20-
message: 'The "urlObj" argument must be of type object. ' +
20+
message: 'The "urlObject" argument must be one of type object or string. ' +
2121
`Received type ${type}`
2222
});
23-
assert.throws(function() { url.format(obj); }, error);
23+
assert.throws(function() { url.format(urlObject); }, error);
2424
}
2525
assert.strictEqual(url.format(''), '');
2626
assert.strictEqual(url.format({}), '');

0 commit comments

Comments
 (0)