diff options
author | Eduardo Leggiero <esleggiero@gmail.com> | 2017-07-03 08:09:11 +0100 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2017-07-05 09:58:47 -0700 |
commit | 8520e6f2804fad64fb50b91c80553715d3c83bd4 (patch) | |
tree | dc40a59176e32c746129adee3cd7d4623328d83a | |
parent | e36917bdc159326665d1e8d14703596780ba0c3a (diff) | |
download | node-new-8520e6f2804fad64fb50b91c80553715d3c83bd4.tar.gz |
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 <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
-rw-r--r-- | lib/url.js | 25 | ||||
-rw-r--r-- | test/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 fcddd4afaf..b3b05f4a89 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 a80cd90586..cc4f6bdc0f 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({}), ''); |