From 8520e6f2804fad64fb50b91c80553715d3c83bd4 Mon Sep 17 00:00:00 2001 From: Eduardo Leggiero Date: Mon, 3 Jul 2017 08:09:11 +0100 Subject: [PATCH] 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 Reviewed-By: Colin Ihrig --- lib/url.js | 25 ++++++++++--------- .../parallel/test-url-format-invalid-input.js | 6 ++--- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/url.js b/lib/url.js index fcddd4afaf2ba7..b3b05f4a89e79b 100644 --- a/lib/url.js +++ b/lib/url.js @@ -550,22 +550,23 @@ function autoEscapeStr(rest) { } // 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. - // If it's an obj, this is a no-op. - // this way, you can call url_format() on strings + // If it's an object, this is a no-op. + // this way, you can call urlParse() on strings // to clean up potentially wonky urls. - if (typeof obj === 'string') { - obj = urlParse(obj); - } else if (typeof obj !== 'object' || obj === null) { - throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'urlObj', 'object', obj); - } else if (!(obj instanceof Url)) { - var format = obj[formatSymbol]; + if (typeof urlObject === 'string') { + urlObject = urlParse(urlObject); + } else if (typeof urlObject !== 'object' || urlObject === null) { + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'urlObject', + ['object', 'string'], urlObject); + } else if (!(urlObject instanceof Url)) { + var format = urlObject[formatSymbol]; return format ? - format.call(obj, options) : - Url.prototype.format.call(obj); + format.call(urlObject, options) : + Url.prototype.format.call(urlObject); } - return obj.format(); + return urlObject.format(); } Url.prototype.format = function format() { diff --git a/test/parallel/test-url-format-invalid-input.js b/test/parallel/test-url-format-invalid-input.js index a80cd9058627db..cc4f6bdc0f178c 100644 --- a/test/parallel/test-url-format-invalid-input.js +++ b/test/parallel/test-url-format-invalid-input.js @@ -13,14 +13,14 @@ const throwsObjsAndReportTypes = new Map([ [Symbol('foo'), 'symbol'] ]); -for (const [obj, type] of throwsObjsAndReportTypes) { +for (const [urlObject, type] of throwsObjsAndReportTypes) { const error = common.expectsError({ code: 'ERR_INVALID_ARG_TYPE', 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}` }); - assert.throws(function() { url.format(obj); }, error); + assert.throws(function() { url.format(urlObject); }, error); } assert.strictEqual(url.format(''), ''); assert.strictEqual(url.format({}), '');