Skip to content

Commit

Permalink
url: fix error message of url.format
Browse files Browse the repository at this point in the history
PR-URL: nodejs#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]>
  • Loading branch information
DavidCai1111 authored and krydos committed Feb 25, 2017
1 parent 431c803 commit f39c7d9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ function urlFormat(obj, options) {
obj = urlParse(obj);
} else if (typeof obj !== 'object' || obj === null) {
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)) {
var format = obj[internalUrl.formatSymbol];
return format ?
Expand Down
25 changes: 14 additions & 11 deletions test/parallel/test-url-format-invalid-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@ require('../common');
const assert = require('assert');
const url = require('url');

// https://github.com/nodejs/node/pull/1036
const throws = [
undefined,
null,
true,
false,
0,
function() {}
];
for (let i = 0; i < throws.length; i++) {
assert.throws(function() { url.format(throws[i]); }, TypeError);
const throwsObjsAndReportTypes = new Map([
[undefined, 'undefined'],
[null, 'null'],
[true, 'boolean'],
[false, 'boolean'],
[0, 'number'],
[function() {}, 'function'],
[Symbol('foo'), 'symbol']
]);

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({}), '');

0 comments on commit f39c7d9

Please sign in to comment.