url: fix error message of url.format
PR-URL: https://github.com/nodejs/node/pull/11162 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
This commit is contained in:
parent
5f20d62c8f
commit
78182458e6
@ -547,7 +547,7 @@ function urlFormat(obj, options) {
|
|||||||
obj = urlParse(obj);
|
obj = urlParse(obj);
|
||||||
} else if (typeof obj !== 'object' || obj === null) {
|
} else if (typeof obj !== 'object' || obj === null) {
|
||||||
throw new TypeError('Parameter "urlObj" must be an object, not ' +
|
throw new TypeError('Parameter "urlObj" must be an object, not ' +
|
||||||
obj === null ? 'null' : typeof obj);
|
(obj === null ? 'null' : typeof obj));
|
||||||
} else if (!(obj instanceof Url)) {
|
} else if (!(obj instanceof Url)) {
|
||||||
var format = obj[internalUrl.formatSymbol];
|
var format = obj[internalUrl.formatSymbol];
|
||||||
return format ?
|
return format ?
|
||||||
|
@ -3,17 +3,20 @@ require('../common');
|
|||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const url = require('url');
|
const url = require('url');
|
||||||
|
|
||||||
// https://github.com/nodejs/node/pull/1036
|
const throwsObjsAndReportTypes = new Map([
|
||||||
const throws = [
|
[undefined, 'undefined'],
|
||||||
undefined,
|
[null, 'null'],
|
||||||
null,
|
[true, 'boolean'],
|
||||||
true,
|
[false, 'boolean'],
|
||||||
false,
|
[0, 'number'],
|
||||||
0,
|
[function() {}, 'function'],
|
||||||
function() {}
|
[Symbol('foo'), 'symbol']
|
||||||
];
|
]);
|
||||||
for (let i = 0; i < throws.length; i++) {
|
|
||||||
assert.throws(function() { url.format(throws[i]); }, TypeError);
|
for (const [obj, type] of throwsObjsAndReportTypes) {
|
||||||
|
const error = new RegExp('^TypeError: Parameter "urlObj" must be an object' +
|
||||||
|
`, not ${type}$`);
|
||||||
|
assert.throws(function() { url.format(obj); }, 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