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 <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>
  • 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.