Skip to content

Commit 7818245

Browse files
DavidCai1111jasnell
authored andcommitted
url: fix error message of url.format
PR-URL: #11162 Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
1 parent 5f20d62 commit 7818245

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

lib/url.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ function urlFormat(obj, options) {
547547
obj = urlParse(obj);
548548
} else if (typeof obj !== 'object' || obj === null) {
549549
throw new TypeError('Parameter "urlObj" must be an object, not ' +
550-
obj === null ? 'null' : typeof obj);
550+
(obj === null ? 'null' : typeof obj));
551551
} else if (!(obj instanceof Url)) {
552552
var format = obj[internalUrl.formatSymbol];
553553
return format ?

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

+14-11
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@ require('../common');
33
const assert = require('assert');
44
const url = require('url');
55

6-
// https://github.com/nodejs/node/pull/1036
7-
const throws = [
8-
undefined,
9-
null,
10-
true,
11-
false,
12-
0,
13-
function() {}
14-
];
15-
for (let i = 0; i < throws.length; i++) {
16-
assert.throws(function() { url.format(throws[i]); }, TypeError);
6+
const throwsObjsAndReportTypes = new Map([
7+
[undefined, 'undefined'],
8+
[null, 'null'],
9+
[true, 'boolean'],
10+
[false, 'boolean'],
11+
[0, 'number'],
12+
[function() {}, 'function'],
13+
[Symbol('foo'), 'symbol']
14+
]);
15+
16+
for (const [obj, type] of throwsObjsAndReportTypes) {
17+
const error = new RegExp('^TypeError: Parameter "urlObj" must be an object' +
18+
`, not ${type}$`);
19+
assert.throws(function() { url.format(obj); }, error);
1720
}
1821
assert.strictEqual(url.format(''), '');
1922
assert.strictEqual(url.format({}), '');

0 commit comments

Comments
 (0)