• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3const assert = require('assert');
4const url = require('url');
5
6// https://github.com/joyent/node/issues/568
7[
8  [undefined, 'undefined'],
9  [null, 'object'],
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  assert.throws(() => {
20    url.parse(val);
21  }, {
22    code: 'ERR_INVALID_ARG_TYPE',
23    name: 'TypeError',
24    message: 'The "url" argument must be of type string.' +
25             common.invalidArgTypeHelper(val)
26  });
27});
28
29assert.throws(() => { url.parse('http://%E0%A4%A@fail'); },
30              (e) => {
31                // The error should be a URIError.
32                if (!(e instanceof URIError))
33                  return false;
34
35                // The error should be from the JS engine and not from Node.js.
36                // JS engine errors do not have the `code` property.
37                return e.code === undefined;
38              });
39