| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent fc46363 commit 473f0ef
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,6 +26,8 @@ const { toASCII } = process.binding('config').hasIntl ? | |||
| 26 | 26 | ||
| 27 | 27 | const { hexTable } = require('internal/querystring'); | |
| 28 | 28 | ||
| 29 | + const errors = require('internal/errors'); | ||
| 30 | + | ||
| 29 | 31 | // WHATWG URL implementation provided by internal/url | |
| 30 | 32 | const { | |
| 31 | 33 | URL, | |
@@ -99,7 +101,7 @@ function urlParse(url, parseQueryString, slashesDenoteHost) { | |||
| 99 | 101 | ||
| 100 | 102 | Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) { | |
| 101 | 103 | if (typeof url !== 'string') { | |
| 102 | - throw new TypeError('Parameter "url" must be a string, not ' + typeof url); | ||
| 104 | + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'url', 'string', url); | ||
| 103 | 105 | } | |
| 104 | 106 | ||
| 105 | 107 | // Copy chrome, IE, opera backslash-handling behavior. | |
@@ -556,8 +558,7 @@ function urlFormat(obj, options) { | |||
| 556 | 558 | if (typeof obj === 'string') { | |
| 557 | 559 | obj = urlParse(obj); | |
| 558 | 560 | } else if (typeof obj !== 'object' || obj === null) { | |
| 559 | - throw new TypeError('Parameter "urlObj" must be an object, not ' + | ||
| 560 | - (obj === null ? 'null' : typeof obj)); | ||
| 561 | + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'urlObj', 'object', obj); | ||
| 561 | 562 | } else if (!(obj instanceof Url)) { | |
| 562 | 563 | var format = obj[formatSymbol]; | |
| 563 | 564 | return format ? | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,5 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | - require('../common'); | ||
| 2 | + const common = require('../common'); | ||
| 3 | 3 | const assert = require('assert'); | |
| 4 | 4 | const url = require('url'); | |
| 5 | 5 | ||
@@ -14,8 +14,12 @@ const throwsObjsAndReportTypes = new Map([ | |||
| 14 | 14 | ]); | |
| 15 | 15 | ||
| 16 | 16 | for (const [obj, type] of throwsObjsAndReportTypes) { | |
| 17 | - const error = new RegExp( | ||
| 18 | - `^TypeError: Parameter "urlObj" must be an object, not ${type}$`); | ||
| 17 | + const error = common.expectsError({ | ||
| 18 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 19 | + type: TypeError, | ||
| 20 | + message: 'The "urlObj" argument must be of type object. ' + | ||
| 21 | + `Received type ${type}` | ||
| 22 | + }); | ||
| 19 | 23 | assert.throws(function() { url.format(obj); }, error); | |
| 20 | 24 | } | |
| 21 | 25 | assert.strictEqual(url.format(''), ''); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,23 +1,27 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | - require('../common'); | ||
| 2 | + const common = require('../common'); | ||
| 3 | 3 | const assert = require('assert'); | |
| 4 | 4 | const url = require('url'); | |
| 5 | 5 | ||
| 6 | 6 | // https://github.com/joyent/node/issues/568 | |
| 7 | - const errMessage = /^TypeError: Parameter "url" must be a string, not (?:undefined|boolean|number|object|function|symbol)$/; | ||
| 8 | 7 | [ | |
| 9 | - undefined, | ||
| 10 | - null, | ||
| 11 | - true, | ||
| 12 | - false, | ||
| 13 | - 0.0, | ||
| 14 | - 0, | ||
| 15 | - [], | ||
| 16 | - {}, | ||
| 17 | - () => {}, | ||
| 18 | - Symbol('foo') | ||
| 19 | - ].forEach((val) => { | ||
| 20 | - assert.throws(() => { url.parse(val); }, errMessage); | ||
| 8 | + [undefined, 'undefined'], | ||
| 9 | + [null, 'null'], | ||
| 10 | + [true, 'boolean'], | ||
| 11 | + [false, 'boolean'], | ||
| 12 | + [0.0, 'number'], | ||
| 13 | + [0, 'number'], | ||
| 14 | + [[], 'object'], | ||
| 15 | + [{}, 'object'], | ||
| 16 | + [() => {}, 'function'], | ||
| 17 | + [Symbol('foo'), 'symbol'] | ||
| 18 | + ].forEach(([val, type]) => { | ||
| 19 | + const error = common.expectsError({ | ||
| 20 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 21 | + type: TypeError, | ||
| 22 | + message: `The "url" argument must be of type string. Received type ${type}` | ||
| 23 | + }); | ||
| 24 | + assert.throws(() => { url.parse(val); }, error); | ||
| 21 | 25 | }); | |
| 22 | 26 | ||
| 23 | 27 | assert.throws(() => { url.parse('http://%E0%A4%A@fail'); }, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments