327b65cb6b
* Use node 7+ WHATWG parser for hostname, fixes #1002 * only use URL if host is IPv6, expose parsed URL * catch invalid URLs, memoize empty obj * hostname returns empty string when URL throws
26 lines
667 B
JavaScript
26 lines
667 B
JavaScript
|
|
'use strict';
|
|
|
|
const request = require('../helpers/context').request;
|
|
const assert = require('assert');
|
|
|
|
describe('req.URL', () => {
|
|
describe('should not throw when', () => {
|
|
it('host is void', () => {
|
|
const req = request();
|
|
assert.doesNotThrow(() => req.URL, TypeError);
|
|
});
|
|
|
|
it('header.host is invalid', () => {
|
|
const req = request();
|
|
req.header.host = 'invalid host';
|
|
assert.doesNotThrow(() => req.URL, TypeError);
|
|
});
|
|
});
|
|
|
|
it('should return empty object when invalid', () => {
|
|
const req = request();
|
|
req.header.host = 'invalid host';
|
|
assert.deepStrictEqual(req.URL, Object.create(null));
|
|
});
|
|
});
|