lib: fix urlObject parameter name in url.format
Documentation, error message, and code now use the same argument name. PR-URL: https://github.com/nodejs/node/pull/14031 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
parent
e36917bdc1
commit
8520e6f280
25
lib/url.js
25
lib/url.js
@ -550,22 +550,23 @@ function autoEscapeStr(rest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// format a parsed object into a url string
|
// format a parsed object into a url string
|
||||||
function urlFormat(obj, options) {
|
function urlFormat(urlObject, options) {
|
||||||
// ensure it's an object, and not a string url.
|
// ensure it's an object, and not a string url.
|
||||||
// If it's an obj, this is a no-op.
|
// If it's an object, this is a no-op.
|
||||||
// this way, you can call url_format() on strings
|
// this way, you can call urlParse() on strings
|
||||||
// to clean up potentially wonky urls.
|
// to clean up potentially wonky urls.
|
||||||
if (typeof obj === 'string') {
|
if (typeof urlObject === 'string') {
|
||||||
obj = urlParse(obj);
|
urlObject = urlParse(urlObject);
|
||||||
} else if (typeof obj !== 'object' || obj === null) {
|
} else if (typeof urlObject !== 'object' || urlObject === null) {
|
||||||
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'urlObj', 'object', obj);
|
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'urlObject',
|
||||||
} else if (!(obj instanceof Url)) {
|
['object', 'string'], urlObject);
|
||||||
var format = obj[formatSymbol];
|
} else if (!(urlObject instanceof Url)) {
|
||||||
|
var format = urlObject[formatSymbol];
|
||||||
return format ?
|
return format ?
|
||||||
format.call(obj, options) :
|
format.call(urlObject, options) :
|
||||||
Url.prototype.format.call(obj);
|
Url.prototype.format.call(urlObject);
|
||||||
}
|
}
|
||||||
return obj.format();
|
return urlObject.format();
|
||||||
}
|
}
|
||||||
|
|
||||||
Url.prototype.format = function format() {
|
Url.prototype.format = function format() {
|
||||||
|
@ -13,14 +13,14 @@ const throwsObjsAndReportTypes = new Map([
|
|||||||
[Symbol('foo'), 'symbol']
|
[Symbol('foo'), 'symbol']
|
||||||
]);
|
]);
|
||||||
|
|
||||||
for (const [obj, type] of throwsObjsAndReportTypes) {
|
for (const [urlObject, type] of throwsObjsAndReportTypes) {
|
||||||
const error = common.expectsError({
|
const error = common.expectsError({
|
||||||
code: 'ERR_INVALID_ARG_TYPE',
|
code: 'ERR_INVALID_ARG_TYPE',
|
||||||
type: TypeError,
|
type: TypeError,
|
||||||
message: 'The "urlObj" argument must be of type object. ' +
|
message: 'The "urlObject" argument must be one of type object or string. ' +
|
||||||
`Received type ${type}`
|
`Received type ${type}`
|
||||||
});
|
});
|
||||||
assert.throws(function() { url.format(obj); }, error);
|
assert.throws(function() { url.format(urlObject); }, error);
|
||||||
}
|
}
|
||||||
assert.strictEqual(url.format(''), '');
|
assert.strictEqual(url.format(''), '');
|
||||||
assert.strictEqual(url.format({}), '');
|
assert.strictEqual(url.format({}), '');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user