2017-01-28 17:23:47 +08:00
|
|
|
'use strict';
|
2017-06-29 00:12:12 +08:00
|
|
|
const common = require('../common');
|
2017-01-28 17:23:47 +08:00
|
|
|
const assert = require('assert');
|
|
|
|
const url = require('url');
|
|
|
|
|
|
|
|
// https://github.com/joyent/node/issues/568
|
|
|
|
[
|
2017-06-29 00:12:12 +08:00
|
|
|
[undefined, 'undefined'],
|
2018-03-19 13:33:46 +01:00
|
|
|
[null, 'object'],
|
2017-06-29 00:12:12 +08:00
|
|
|
[true, 'boolean'],
|
|
|
|
[false, 'boolean'],
|
|
|
|
[0.0, 'number'],
|
|
|
|
[0, 'number'],
|
|
|
|
[[], 'object'],
|
|
|
|
[{}, 'object'],
|
|
|
|
[() => {}, 'function'],
|
|
|
|
[Symbol('foo'), 'symbol']
|
|
|
|
].forEach(([val, type]) => {
|
2019-12-25 18:02:16 +01:00
|
|
|
assert.throws(() => {
|
2018-01-05 13:13:51 +05:30
|
|
|
url.parse(val);
|
|
|
|
}, {
|
2017-06-29 00:12:12 +08:00
|
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
2019-12-25 18:02:16 +01:00
|
|
|
name: 'TypeError',
|
2019-09-23 08:17:25 +02:00
|
|
|
message: 'The "url" argument must be of type string.' +
|
|
|
|
common.invalidArgTypeHelper(val)
|
2017-06-29 00:12:12 +08:00
|
|
|
});
|
2017-01-28 17:23:47 +08:00
|
|
|
});
|
2017-03-30 13:21:49 +01:00
|
|
|
|
2017-05-07 14:12:30 +03:00
|
|
|
assert.throws(() => { url.parse('http://%E0%A4%A@fail'); },
|
2018-06-04 13:10:09 +00:00
|
|
|
(e) => {
|
|
|
|
// The error should be a URIError.
|
|
|
|
if (!(e instanceof URIError))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// The error should be from the JS engine and not from Node.js.
|
|
|
|
// JS engine errors do not have the `code` property.
|
|
|
|
return e.code === undefined;
|
|
|
|
});
|