Comparing version 2.0.2 to 3.0.0
128
lib/index.js
@@ -0,7 +1,9 @@ | ||
'use strict'; | ||
// Load modules | ||
var Hoek = require('hoek'); | ||
var Boom = require('boom'); | ||
var Regex = require('./regex'); | ||
var Segment = require('./segment'); | ||
const Hoek = require('hoek'); | ||
const Boom = require('boom'); | ||
const Regex = require('./regex'); | ||
const Segment = require('./segment'); | ||
@@ -11,3 +13,3 @@ | ||
var internals = { | ||
const internals = { | ||
pathRegex: Regex.generate(), | ||
@@ -38,17 +40,15 @@ defaults: { | ||
var self = this; | ||
const method = config.method.toLowerCase(); | ||
var method = config.method.toLowerCase(); | ||
var vhost = config.vhost || '*'; | ||
const vhost = config.vhost || '*'; | ||
if (vhost !== '*') { | ||
self.vhosts = self.vhosts || {}; | ||
self.vhosts[vhost] = self.vhosts[vhost] || {}; | ||
this.vhosts = this.vhosts || {}; | ||
this.vhosts[vhost] = this.vhosts[vhost] || {}; | ||
} | ||
var table = (vhost === '*' ? self.routes : self.vhosts[vhost]); | ||
const table = (vhost === '*' ? this.routes : this.vhosts[vhost]); | ||
table[method] = table[method] || { routes: [], router: new Segment() }; | ||
var analysis = config.analysis || this.analyze(config.path); | ||
var record = { | ||
const analysis = config.analysis || this.analyze(config.path); | ||
const record = { | ||
path: config.path, | ||
@@ -68,3 +68,3 @@ route: route || config.path, | ||
var last = record.segments[record.segments.length - 1]; | ||
const last = record.segments[record.segments.length - 1]; | ||
if (last.empty) { | ||
@@ -93,6 +93,6 @@ table[method].router.add(analysis.segments.slice(0, -1), record); | ||
var segments = path.split('/').slice(1); | ||
const segments = path.split('/').slice(1); | ||
var vhost = (this.vhosts && hostname && this.vhosts[hostname]); | ||
var route = (vhost && this._lookup(path, segments, vhost, method)) || | ||
const vhost = (this.vhosts && hostname && this.vhosts[hostname]); | ||
const route = (vhost && this._lookup(path, segments, vhost, method)) || | ||
this._lookup(path, segments, this.routes, method) || | ||
@@ -112,3 +112,3 @@ (method === 'head' && vhost && this._lookup(path, segments, vhost, 'get')) || | ||
var set = table[method]; | ||
const set = table[method]; | ||
if (!set) { | ||
@@ -118,3 +118,3 @@ return null; | ||
var match = set.router.lookup(path, segments, this.settings); | ||
const match = set.router.lookup(path, segments, this.settings); | ||
if (!match) { | ||
@@ -124,7 +124,7 @@ return null; | ||
var assignments = {}; | ||
var array = []; | ||
for (var i = 0, il = match.array.length; i < il; ++i) { | ||
var name = match.record.params[i]; | ||
var value = match.array[i]; | ||
const assignments = {}; | ||
const array = []; | ||
for (let i = 0; i < match.array.length; ++i) { | ||
const name = match.record.params[i]; | ||
let value = match.array[i]; | ||
if (value) { | ||
@@ -137,3 +137,3 @@ value = internals.decode(value); | ||
if (assignments[name] !== undefined) { | ||
assignments[name] += '/' + value; | ||
assignments[name] = assignments[name] + '/' + value; | ||
} | ||
@@ -144,3 +144,3 @@ else { | ||
if (i + 1 === il || | ||
if (i + 1 === match.array.length || | ||
name !== match.record.params[i + 1]) { | ||
@@ -175,7 +175,4 @@ | ||
var uppercase = path.replace(/%[0-9a-fA-F][0-9a-fA-F]/g, function (encoded) { | ||
const uppercase = path.replace(/%[0-9a-fA-F][0-9a-fA-F]/g, (encoded) => encoded.toUpperCase()); | ||
return encoded.toUpperCase(); | ||
}); | ||
// Decode non-reserved path characters: a-z A-Z 0-9 _!$&'()*+,;=:@-.~ | ||
@@ -186,7 +183,4 @@ // ! (%21) $ (%24) & (%26) ' (%27) ( (%28) ) (%29) * (%2A) + (%2B) , (%2C) - (%2D) . (%2E) | ||
var decoded = uppercase.replace(/%(?:2[146-9A-E]|3[\dABD]|4[\dA-F]|5[\dAF]|6[1-9A-F]|7[\dAE])/g, function (encoded) { | ||
const decoded = uppercase.replace(/%(?:2[146-9A-E]|3[\dABD]|4[\dA-F]|5[\dAF]|6[1-9A-F]|7[\dAE])/g, (encoded) => String.fromCharCode(parseInt(encoded.substring(1), 16))); | ||
return String.fromCharCode(parseInt(encoded.substring(1), 16)); | ||
}); | ||
path = decoded; | ||
@@ -204,9 +198,9 @@ } | ||
var pathParts = path.split('/'); | ||
var segments = []; | ||
var params = []; | ||
var fingers = []; | ||
const pathParts = path.split('/'); | ||
const segments = []; | ||
const params = []; | ||
const fingers = []; | ||
for (var i = 1, il = pathParts.length; i < il; ++i) { // Skip first empty segment | ||
var segment = pathParts[i]; | ||
for (let i = 1; i < pathParts.length; ++i) { // Skip first empty segment | ||
let segment = pathParts[i]; | ||
@@ -224,3 +218,3 @@ // Literal | ||
var parts = internals.parseParams(segment); | ||
const parts = internals.parseParams(segment); | ||
if (parts.length === 1) { | ||
@@ -230,3 +224,3 @@ | ||
var item = parts[0]; | ||
const item = parts[0]; | ||
Hoek.assert(params.indexOf(item.name) === -1, 'Cannot repeat the same parameter name:', item.name, 'in:', path); | ||
@@ -237,6 +231,6 @@ params.push(item.name); | ||
if (item.count) { | ||
for (var m = 0; m < item.count; ++m) { | ||
for (let j = 0; j < item.count; ++j) { | ||
fingers.push('?'); | ||
segments.push({}); | ||
if (m) { | ||
if (j) { | ||
params.push(item.name); | ||
@@ -260,3 +254,3 @@ } | ||
var seg = { | ||
const seg = { | ||
length: parts.length, | ||
@@ -267,9 +261,9 @@ first: typeof parts[0] !== 'string', | ||
var finger = ''; | ||
var regex = '^'; | ||
for (var p = 0, pl = parts.length; p < pl; ++p) { | ||
var part = parts[p]; | ||
let finger = ''; | ||
let regex = '^'; | ||
for (let j = 0; j < parts.length; ++j) { | ||
const part = parts[j]; | ||
if (typeof part === 'string') { | ||
finger += part; | ||
regex += Hoek.escapeRegex(part); | ||
finger = finger + part; | ||
regex = regex + Hoek.escapeRegex(part); | ||
seg.segments.push(part); | ||
@@ -281,4 +275,4 @@ } | ||
finger += '?'; | ||
regex += '(.' + (part.empty ? '*' : '+') + ')'; | ||
finger = finger + '?'; | ||
regex = regex + '(.' + (part.empty ? '*' : '+') + ')'; | ||
} | ||
@@ -303,4 +297,4 @@ } | ||
var parts = []; | ||
segment.replace(internals.pathRegex.parseParam, function (match, literal, name, wilcard, count, empty) { | ||
const parts = []; | ||
segment.replace(internals.pathRegex.parseParam, (match, literal, name, wilcard, count, empty) => { | ||
@@ -328,4 +322,4 @@ if (literal) { | ||
var result = []; | ||
var collect = function (table) { | ||
const result = []; | ||
const collect = (table) => { | ||
@@ -336,5 +330,5 @@ if (!table) { | ||
Object.keys(table).forEach(function (method) { | ||
Object.keys(table).forEach((method) => { | ||
table[method].routes.forEach(function (record) { | ||
table[method].routes.forEach((record) => { | ||
@@ -347,4 +341,4 @@ result.push(record.route); | ||
if (this.vhosts) { | ||
var vhosts = host ? [].concat(host) : Object.keys(this.vhosts); | ||
for (var i = 0, il = vhosts.length; i < il; ++i) { | ||
const vhosts = host ? [].concat(host) : Object.keys(this.vhosts); | ||
for (let i = 0; i < vhosts.length; ++i) { | ||
collect(this.vhosts[vhosts[i]]); | ||
@@ -362,7 +356,7 @@ } | ||
var aFirst = -1; | ||
var bFirst = 1; | ||
const aFirst = -1; | ||
const bFirst = 1; | ||
var as = a.segments; | ||
var bs = b.segments; | ||
const as = a.segments; | ||
const bs = b.segments; | ||
@@ -373,3 +367,3 @@ if (as.length !== bs.length) { | ||
for (var i = 0, il = as.length; ; ++i) { | ||
for (let i = 0; ; ++i) { | ||
if (as[i].literal) { | ||
@@ -376,0 +370,0 @@ if (bs[i].literal) { |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
// Load modules | ||
@@ -6,3 +8,3 @@ | ||
var internals = {}; | ||
const internals = {}; | ||
@@ -20,27 +22,27 @@ | ||
var empty = '(?:^\\/$)'; | ||
const empty = '(?:^\\/$)'; | ||
var legalChars = '[\\w\\!\\$&\'\\(\\)\\*\\+\\,;\\=\\:@\\-\\.~]'; | ||
var encoded = '%[A-F0-9]{2}'; | ||
const legalChars = '[\\w\\!\\$&\'\\(\\)\\*\\+\\,;\\=\\:@\\-\\.~]'; | ||
const encoded = '%[A-F0-9]{2}'; | ||
var literalChar = '(?:' + legalChars + '|' + encoded + ')'; | ||
var literal = literalChar + '+'; | ||
var literalOptional = literalChar + '*'; | ||
const literalChar = '(?:' + legalChars + '|' + encoded + ')'; | ||
const literal = literalChar + '+'; | ||
const literalOptional = literalChar + '*'; | ||
var midParam = '(?:\\{\\w+(?:\\*[1-9]\\d*)?\\})'; // {p}, {p*2} | ||
var endParam = '(?:\\/(?:\\{\\w+(?:(?:\\*(?:[1-9]\\d*)?)|(?:\\?))?\\})?)?'; // {p}, {p*2}, {p*}, {p?} | ||
const midParam = '(?:\\{\\w+(?:\\*[1-9]\\d*)?\\})'; // {p}, {p*2} | ||
const endParam = '(?:\\/(?:\\{\\w+(?:(?:\\*(?:[1-9]\\d*)?)|(?:\\?))?\\})?)?'; // {p}, {p*2}, {p*}, {p?} | ||
var partialParam = '(?:\\{\\w+\\??\\})'; // {p}, {p?} | ||
var mixedParam = '(?:(?:' + literal + partialParam + ')+' + literalOptional + ')|(?:' + partialParam + '(?:' + literal + partialParam + ')+' + literalOptional + ')|(?:' + partialParam + literal + ')'; | ||
const partialParam = '(?:\\{\\w+\\??\\})'; // {p}, {p?} | ||
const mixedParam = '(?:(?:' + literal + partialParam + ')+' + literalOptional + ')|(?:' + partialParam + '(?:' + literal + partialParam + ')+' + literalOptional + ')|(?:' + partialParam + literal + ')'; | ||
var segmentContent = '(?:' + literal + '|' + midParam + '|' + mixedParam + ')'; | ||
var segment = '\\/' + segmentContent; | ||
var segments = '(?:' + segment + ')*'; | ||
const segmentContent = '(?:' + literal + '|' + midParam + '|' + mixedParam + ')'; | ||
const segment = '\\/' + segmentContent; | ||
const segments = '(?:' + segment + ')*'; | ||
var path = '(?:^' + segments + endParam + '$)'; | ||
const path = '(?:^' + segments + endParam + '$)'; | ||
// 1:literal 2:name 3:* 4:count 5:? | ||
var parseParam = '(' + literal + ')|(?:\\{(\\w+)(?:(\\*)(\\d+)?)?(\\?)?\\})'; | ||
const parseParam = '(' + literal + ')|(?:\\{(\\w+)(?:(\\*)(\\d+)?)?(\\?)?\\})'; | ||
var expressions = { | ||
const expressions = { | ||
parseParam: new RegExp(parseParam, 'g'), | ||
@@ -47,0 +49,0 @@ validatePath: new RegExp(empty + '|' + path), |
@@ -0,5 +1,6 @@ | ||
'use strict'; | ||
// Load modules | ||
var Hoek = require('hoek'); | ||
var Boom = require('boom'); | ||
const Hoek = require('hoek'); | ||
@@ -9,3 +10,3 @@ | ||
var internals = {}; | ||
const internals = {}; | ||
@@ -33,8 +34,9 @@ | ||
var current = segments[0]; | ||
var remaining = segments.slice(1); | ||
var isEdge = !remaining.length; | ||
const current = segments[0]; | ||
const remaining = segments.slice(1); | ||
const isEdge = !remaining.length; | ||
var literals = []; | ||
for (var i = 0, il = segments.length, isLiteral = true; i < il && isLiteral; ++i) { | ||
const literals = []; | ||
let isLiteral = true; | ||
for (let i = 0; i < segments.length && isLiteral; ++i) { | ||
isLiteral = segments[i].literal !== undefined; | ||
@@ -46,3 +48,3 @@ literals.push(segments[i].literal); | ||
this._fulls = this._fulls || {}; | ||
var literal = '/' + literals.join('/'); | ||
let literal = '/' + literals.join('/'); | ||
if (!record.settings.isCaseSensitive) { | ||
@@ -60,3 +62,3 @@ literal = literal.toLowerCase(); | ||
this._literals = this._literals || {}; | ||
var currentLiteral = (record.settings.isCaseSensitive ? current.literal : current.literal.toLowerCase()); | ||
const currentLiteral = (record.settings.isCaseSensitive ? current.literal : current.literal.toLowerCase()); | ||
this._literals[currentLiteral] = this._literals[currentLiteral] || new internals.Segment(); | ||
@@ -79,3 +81,3 @@ this._literals[currentLiteral].add(remaining, record); | ||
var mixed = this._mixedLookup(current); | ||
let mixed = this._mixedLookup(current); | ||
if (!mixed) { | ||
@@ -115,3 +117,3 @@ mixed = { segment: current, node: new internals.Segment() }; | ||
for (var i = 0, il = this._mixed.length; i < il; ++i) { | ||
for (let i = 0; i < this._mixed.length; ++i) { | ||
if (internals.mixed({ segment: segment }, this._mixed[i]) === 0) { | ||
@@ -128,7 +130,7 @@ return this._mixed[i]; | ||
var aFirst = -1; | ||
var bFirst = 1; | ||
const aFirst = -1; | ||
const bFirst = 1; | ||
var as = a.segment; | ||
var bs = b.segment; | ||
const as = a.segment; | ||
const bs = b.segment; | ||
@@ -143,5 +145,5 @@ if (as.length !== bs.length) { | ||
for (var j = 0, jl = as.segments.length; j < jl; ++j) { | ||
var am = as.segments[j]; | ||
var bm = bs.segments[j]; | ||
for (let i = 0; i < as.segments.length; ++i) { | ||
const am = as.segments[i]; | ||
const bm = bs.segments[i]; | ||
@@ -165,3 +167,3 @@ if (am === bm) { | ||
var match = null; | ||
let match = null; | ||
@@ -179,5 +181,5 @@ // Literal edge | ||
var current = segments[0]; | ||
var nextPath = path.slice(current.length + 1); | ||
var remainder = (segments.length > 1 ? segments.slice(1) : null); | ||
const current = segments[0]; | ||
const nextPath = path.slice(current.length + 1); | ||
const remainder = (segments.length > 1 ? segments.slice(1) : null); | ||
@@ -187,3 +189,3 @@ if (this._literals) { | ||
if (match) { | ||
var record = internals.deeper(match, nextPath, remainder, [], options); | ||
const record = internals.deeper(match, nextPath, remainder, [], options); | ||
if (record) { | ||
@@ -198,12 +200,12 @@ return record; | ||
if (this._mixed) { | ||
for (var i = 0, il = this._mixed.length; i < il; ++i) { | ||
for (let i = 0; i < this._mixed.length; ++i) { | ||
match = this._mixed[i]; | ||
var params = current.match(match.segment.mixed); | ||
const params = current.match(match.segment.mixed); | ||
if (params) { | ||
var array = []; | ||
for (var p = 1, pl = params.length; p < pl; ++p) { | ||
array.push(params[p]); | ||
const array = []; | ||
for (let j = 1; j < params.length; ++j) { | ||
array.push(params[j]); | ||
} | ||
record = internals.deeper(match.node, nextPath, remainder, array, options); | ||
const record = internals.deeper(match.node, nextPath, remainder, array, options); | ||
if (record) { | ||
@@ -223,3 +225,3 @@ return record; | ||
record = internals.deeper(this._param, nextPath, remainder, [current], options); | ||
const record = internals.deeper(this._param, nextPath, remainder, [current], options); | ||
if (record) { | ||
@@ -253,3 +255,3 @@ return record; | ||
else { | ||
var result = match.lookup(path, segments, options); | ||
const result = match.lookup(path, segments, options); | ||
if (result) { | ||
@@ -256,0 +258,0 @@ return { record: result.record, array: array.concat(result.array) }; |
{ | ||
"name": "call", | ||
"description": "HTTP Router", | ||
"version": "2.0.2", | ||
"version": "3.0.0", | ||
"repository": "git://github.com/hapijs/call", | ||
@@ -12,11 +12,11 @@ "main": "lib/index.js", | ||
"engines": { | ||
"node": ">=0.10.32" | ||
"node": ">=4.0.0" | ||
}, | ||
"dependencies": { | ||
"hoek": "2.x.x", | ||
"boom": "2.x.x" | ||
"hoek": "3.x.x", | ||
"boom": "3.x.x" | ||
}, | ||
"devDependencies": { | ||
"code": "1.x.x", | ||
"lab": "5.x.x" | ||
"code": "2.x.x", | ||
"lab": "7.x.x" | ||
}, | ||
@@ -23,0 +23,0 @@ "scripts": { |
@@ -0,6 +1,8 @@ | ||
'use strict'; | ||
// Load modules | ||
var Lab = require('lab'); | ||
var Call = require('../'); | ||
var Code = require('code'); | ||
const Lab = require('lab'); | ||
const Call = require('../'); | ||
const Code = require('code'); | ||
@@ -10,3 +12,3 @@ | ||
var internals = {}; | ||
const internals = {}; | ||
@@ -16,13 +18,13 @@ | ||
var lab = exports.lab = Lab.script(); | ||
var describe = lab.describe; | ||
var it = lab.it; | ||
var expect = Code.expect; | ||
const lab = exports.lab = Lab.script(); | ||
const describe = lab.describe; | ||
const it = lab.it; | ||
const expect = Code.expect; | ||
describe('Router', function () { | ||
describe('Router', () => { | ||
it('routes request', function (done) { | ||
it('routes request', (done) => { | ||
var router = new Call.Router(); | ||
const router = new Call.Router(); | ||
router.add({ method: 'get', path: '/' }, '/'); | ||
@@ -39,5 +41,5 @@ router.add({ method: 'get', path: '/a' }, '/a'); | ||
it('routes request (pre-analyzed)', function (done) { | ||
it('routes request (pre-analyzed)', (done) => { | ||
var router = new Call.Router(); | ||
const router = new Call.Router(); | ||
router.add({ method: 'get', path: '/', analysis: router.analyze('/') }, '/'); | ||
@@ -54,5 +56,5 @@ router.add({ method: 'get', path: '/a', analysis: router.analyze('/a') }, '/a'); | ||
describe('sort', function () { | ||
describe('sort', () => { | ||
var paths = [ | ||
const paths = [ | ||
'/', | ||
@@ -97,8 +99,8 @@ '/a', | ||
var router = new Call.Router(); | ||
for (var i = 0, il = paths.length; i < il; ++i) { | ||
const router = new Call.Router(); | ||
for (let i = 0; i < paths.length; ++i) { | ||
router.add({ method: 'get', path: paths[i] }, paths[i]); | ||
} | ||
var requests = [ | ||
const requests = [ | ||
['/', '/'], | ||
@@ -144,5 +146,5 @@ ['/a', '/a'], | ||
var test = function (path, route) { | ||
const test = function (path, route) { | ||
it('matches \'' + path + '\' to \'' + route + '\'', function (done) { | ||
it('matches \'' + path + '\' to \'' + route + '\'', (done) => { | ||
@@ -154,3 +156,3 @@ expect(router.route('get', path).route).to.equal(route); | ||
for (i = 0, il = requests.length; i < il; ++i) { | ||
for (let i = 0; i < requests.length; ++i) { | ||
test(requests[i][0], requests[i][1]); | ||
@@ -160,7 +162,7 @@ } | ||
describe('add()', function () { | ||
describe('add()', () => { | ||
it('adds a route with id', function (done) { | ||
it('adds a route with id', (done) => { | ||
var router = new Call.Router(); | ||
const router = new Call.Router(); | ||
router.add({ method: 'get', path: '/a/b/{c}', id: 'a' }); | ||
@@ -171,7 +173,7 @@ expect(router.ids.a.path).to.equal('/a/b/{c}'); | ||
it('throws on duplicate route', function (done) { | ||
it('throws on duplicate route', (done) => { | ||
var router = new Call.Router(); | ||
const router = new Call.Router(); | ||
router.add({ method: 'get', path: '/a/b/{c}' }); | ||
expect(function () { | ||
expect(() => { | ||
@@ -184,7 +186,7 @@ router.add({ method: 'get', path: '/a/b/{c}' }); | ||
it('throws on duplicate route (id)', function (done) { | ||
it('throws on duplicate route (id)', (done) => { | ||
var router = new Call.Router(); | ||
const router = new Call.Router(); | ||
router.add({ method: 'get', path: '/a/b', id: '1' }); | ||
expect(function () { | ||
expect(() => { | ||
@@ -197,7 +199,7 @@ router.add({ method: 'get', path: '/b', id: '1' }); | ||
it('throws on duplicate route (optional param in first)', function (done) { | ||
it('throws on duplicate route (optional param in first)', (done) => { | ||
var router = new Call.Router(); | ||
const router = new Call.Router(); | ||
router.add({ method: 'get', path: '/a/b/{c?}' }); | ||
expect(function () { | ||
expect(() => { | ||
@@ -210,7 +212,7 @@ router.add({ method: 'get', path: '/a/b' }); | ||
it('throws on duplicate route (optional param in second)', function (done) { | ||
it('throws on duplicate route (optional param in second)', (done) => { | ||
var router = new Call.Router(); | ||
const router = new Call.Router(); | ||
router.add({ method: 'get', path: '/a/b' }); | ||
expect(function () { | ||
expect(() => { | ||
@@ -223,7 +225,7 @@ router.add({ method: 'get', path: '/a/b/{c?}' }); | ||
it('throws on duplicate route (same fingerprint)', function (done) { | ||
it('throws on duplicate route (same fingerprint)', (done) => { | ||
var router = new Call.Router(); | ||
const router = new Call.Router(); | ||
router.add({ method: 'get', path: '/test/{p1}/{p2}/end' }); | ||
expect(function () { | ||
expect(() => { | ||
@@ -236,7 +238,7 @@ router.add({ method: 'get', path: '/test/{p*2}/end' }); | ||
it('throws on duplicate route (case insensitive)', function (done) { | ||
it('throws on duplicate route (case insensitive)', (done) => { | ||
var router = new Call.Router({ isCaseSensitive: false }); | ||
const router = new Call.Router({ isCaseSensitive: false }); | ||
router.add({ method: 'get', path: '/test/a' }); | ||
expect(function () { | ||
expect(() => { | ||
@@ -249,7 +251,7 @@ router.add({ method: 'get', path: '/test/A' }); | ||
it('throws on duplicate route (wildcards)', function (done) { | ||
it('throws on duplicate route (wildcards)', (done) => { | ||
var router = new Call.Router(); | ||
const router = new Call.Router(); | ||
router.add({ method: 'get', path: '/a/b/{c*}' }); | ||
expect(function () { | ||
expect(() => { | ||
@@ -262,7 +264,7 @@ router.add({ method: 'get', path: '/a/b/{c*}' }); | ||
it('throws on duplicate route (mixed)', function (done) { | ||
it('throws on duplicate route (mixed)', (done) => { | ||
var router = new Call.Router(); | ||
const router = new Call.Router(); | ||
router.add({ method: 'get', path: '/a/b/a{c}' }); | ||
expect(function () { | ||
expect(() => { | ||
@@ -275,7 +277,7 @@ router.add({ method: 'get', path: '/a/b/a{c}' }); | ||
it('throws on duplicate route (/a/{p}/{q*}, /a/{p*})', function (done) { | ||
it('throws on duplicate route (/a/{p}/{q*}, /a/{p*})', (done) => { | ||
var router = new Call.Router(); | ||
const router = new Call.Router(); | ||
router.add({ method: 'get', path: '/a/{p}/{q*}' }); | ||
expect(function () { | ||
expect(() => { | ||
@@ -288,7 +290,7 @@ router.add({ method: 'get', path: '/a/{p*}' }); | ||
it('throws on duplicate route (/a/{p*}, /a/{p}/{q*})', function (done) { | ||
it('throws on duplicate route (/a/{p*}, /a/{p}/{q*})', (done) => { | ||
var router = new Call.Router(); | ||
const router = new Call.Router(); | ||
router.add({ method: 'get', path: '/a/{p*}' }); | ||
expect(function () { | ||
expect(() => { | ||
@@ -301,7 +303,7 @@ router.add({ method: 'get', path: '/a/{p}/{q*}' }); | ||
it('allows route to differ in just case', function (done) { | ||
it('allows route to differ in just case', (done) => { | ||
var router = new Call.Router(); | ||
const router = new Call.Router(); | ||
router.add({ method: 'get', path: '/test/a' }); | ||
expect(function () { | ||
expect(() => { | ||
@@ -314,7 +316,7 @@ router.add({ method: 'get', path: '/test/A' }); | ||
it('throws on duplicate route (different param name)', function (done) { | ||
it('throws on duplicate route (different param name)', (done) => { | ||
var router = new Call.Router(); | ||
const router = new Call.Router(); | ||
router.add({ method: 'get', path: '/test/{p}' }); | ||
expect(function () { | ||
expect(() => { | ||
@@ -327,6 +329,6 @@ router.add({ method: 'get', path: '/test/{P}' }); | ||
it('throws on duplicate parameter name', function (done) { | ||
it('throws on duplicate parameter name', (done) => { | ||
var router = new Call.Router(); | ||
expect(function () { | ||
const router = new Call.Router(); | ||
expect(() => { | ||
@@ -339,6 +341,6 @@ router.add({ method: 'get', path: '/test/{p}/{p}' }); | ||
it('throws on invalid path', function (done) { | ||
it('throws on invalid path', (done) => { | ||
var router = new Call.Router(); | ||
expect(function () { | ||
const router = new Call.Router(); | ||
expect(() => { | ||
@@ -351,7 +353,7 @@ router.add({ method: 'get', path: '/%/%' }); | ||
it('throws on duplicate route (same vhost)', function (done) { | ||
it('throws on duplicate route (same vhost)', (done) => { | ||
var router = new Call.Router(); | ||
const router = new Call.Router(); | ||
router.add({ method: 'get', path: '/a/b/{c}', vhost: 'example.com' }); | ||
expect(function () { | ||
expect(() => { | ||
@@ -364,7 +366,7 @@ router.add({ method: 'get', path: '/a/b/{c}', vhost: 'example.com' }); | ||
it('allows duplicate route (different vhost)', function (done) { | ||
it('allows duplicate route (different vhost)', (done) => { | ||
var router = new Call.Router(); | ||
const router = new Call.Router(); | ||
router.add({ method: 'get', path: '/a/b/{c}', vhost: 'one.example.com' }); | ||
expect(function () { | ||
expect(() => { | ||
@@ -378,7 +380,7 @@ router.add({ method: 'get', path: '/a/b/{c}', vhost: 'two.example.com' }); | ||
describe('special()', function () { | ||
describe('special()', () => { | ||
it('returns special not found route', function (done) { | ||
it('returns special not found route', (done) => { | ||
var router = new Call.Router(); | ||
const router = new Call.Router(); | ||
router.special('notFound', 'x'); | ||
@@ -389,5 +391,5 @@ expect(router.route('get', '/').route).to.equal('x'); | ||
it('returns special bad request route', function (done) { | ||
it('returns special bad request route', (done) => { | ||
var router = new Call.Router(); | ||
const router = new Call.Router(); | ||
router.add({ method: 'get', path: '/{p}' }); | ||
@@ -399,5 +401,5 @@ router.special('badRequest', 'x'); | ||
it('returns special options route', function (done) { | ||
it('returns special options route', (done) => { | ||
var router = new Call.Router(); | ||
const router = new Call.Router(); | ||
router.special('options', 'x'); | ||
@@ -409,5 +411,5 @@ expect(router.route('options', '/').route).to.equal('x'); | ||
describe('route()', function () { | ||
describe('route()', () => { | ||
var paths = { | ||
const paths = { | ||
'/path/to/|false': { | ||
@@ -573,27 +575,27 @@ '/path/to': false, | ||
var test = function (path, matches, isCaseSensitive) { | ||
const test = function (path, matches, isCaseSensitive) { | ||
var router = new Call.Router({ isCaseSensitive: isCaseSensitive }); | ||
const router = new Call.Router({ isCaseSensitive: isCaseSensitive }); | ||
router.add({ path: path, method: 'get' }, path); | ||
var mkeys = Object.keys(matches); | ||
for (var m = 0, ml = mkeys.length; m < ml; ++m) { | ||
match(router, path, mkeys[m], matches[mkeys[m]], isCaseSensitive); | ||
const mkeys = Object.keys(matches); | ||
for (let i = 0; i < mkeys.length; ++i) { | ||
match(router, path, mkeys[i], matches[mkeys[i]], isCaseSensitive); | ||
} | ||
}; | ||
var match = function (router, path, compare, result, isCaseSensitive) { | ||
const match = function (router, path, compare, result, isCaseSensitive) { | ||
it((result ? 'matches' : 'unmatches') + ' the path \'' + path + '\' with ' + compare + ' (' + (isCaseSensitive ? 'case-sensitive' : 'case-insensitive') + ')', function (done) { | ||
it((result ? 'matches' : 'unmatches') + ' the path \'' + path + '\' with ' + compare + ' (' + (isCaseSensitive ? 'case-sensitive' : 'case-insensitive') + ')', (done) => { | ||
var output = router.route('get', router.normalize(compare)); | ||
var isMatch = !output.isBoom; | ||
const output = router.route('get', router.normalize(compare)); | ||
const isMatch = !output.isBoom; | ||
expect(isMatch).to.equal(!!result); | ||
if (typeof result === 'object') { | ||
var ps = Object.keys(result); | ||
const ps = Object.keys(result); | ||
expect(ps.length).to.equal(output.paramsArray.length); | ||
for (var p = 0, pl = ps.length; p < pl; ++p) { | ||
expect(output.params[ps[p]]).to.equal(result[ps[p]]); | ||
for (let i = 0; i < ps.length; ++i) { | ||
expect(output.params[ps[i]]).to.equal(result[ps[i]]); | ||
} | ||
@@ -606,12 +608,12 @@ } | ||
var keys = Object.keys(paths); | ||
for (var i = 0, il = keys.length; i < il; ++i) { | ||
var pathParts = keys[i].split('|'); | ||
var sensitive = (pathParts[1] ? pathParts[1] === 'true' : true); | ||
const keys = Object.keys(paths); | ||
for (let i = 0; i < keys.length; ++i) { | ||
const pathParts = keys[i].split('|'); | ||
const sensitive = (pathParts[1] ? pathParts[1] === 'true' : true); | ||
test(pathParts[0], paths[keys[i]], sensitive); | ||
} | ||
it('matches head routes', function (done) { | ||
it('matches head routes', (done) => { | ||
var router = new Call.Router(); | ||
const router = new Call.Router(); | ||
router.add({ method: 'get', path: '/a' }, 'a'); | ||
@@ -634,5 +636,5 @@ router.add({ method: 'get', path: '/a', vhost: 'special.example.com' }, 'b'); | ||
it('matches * routes', function (done) { | ||
it('matches * routes', (done) => { | ||
var router = new Call.Router(); | ||
const router = new Call.Router(); | ||
router.add({ method: '*', path: '/a' }, 'a'); | ||
@@ -646,5 +648,5 @@ router.add({ method: '*', path: '/a', vhost: 'special.example.com' }, 'b'); | ||
it('fails to match head request', function (done) { | ||
it('fails to match head request', (done) => { | ||
var router = new Call.Router(); | ||
const router = new Call.Router(); | ||
expect(router.route('head', '/').output.statusCode).to.equal(404); | ||
@@ -654,5 +656,5 @@ done(); | ||
it('fails to match options request', function (done) { | ||
it('fails to match options request', (done) => { | ||
var router = new Call.Router(); | ||
const router = new Call.Router(); | ||
expect(router.route('options', '/').output.statusCode).to.equal(404); | ||
@@ -662,5 +664,5 @@ done(); | ||
it('fails to match get request with vhost (table exists but not route)', function (done) { | ||
it('fails to match get request with vhost (table exists but not route)', (done) => { | ||
var router = new Call.Router(); | ||
const router = new Call.Router(); | ||
router.add({ method: 'get', path: '/', vhost: 'special.example.com' }); | ||
@@ -671,5 +673,5 @@ expect(router.route('get', '/x', 'special.example.com').output.statusCode).to.equal(404); | ||
it('fails to match head request with vhost (table exists but not route)', function (done) { | ||
it('fails to match head request with vhost (table exists but not route)', (done) => { | ||
var router = new Call.Router(); | ||
const router = new Call.Router(); | ||
router.add({ method: 'head', path: '/', vhost: 'special.example.com' }); | ||
@@ -680,5 +682,5 @@ expect(router.route('head', '/x', 'special.example.com').output.statusCode).to.equal(404); | ||
it('fails to match bad request', function (done) { | ||
it('fails to match bad request', (done) => { | ||
var router = new Call.Router(); | ||
const router = new Call.Router(); | ||
router.add({ method: 'get', path: '/{p}' }); | ||
@@ -689,5 +691,5 @@ expect(router.route('get', '/%p').output.statusCode).to.equal(400); | ||
it('fails to match bad request (mixed)', function (done) { | ||
it('fails to match bad request (mixed)', (done) => { | ||
var router = new Call.Router(); | ||
const router = new Call.Router(); | ||
router.add({ method: 'get', path: '/a{p}' }); | ||
@@ -698,5 +700,5 @@ expect(router.route('get', '/a%p').output.statusCode).to.equal(400); | ||
it('fails to match bad request (wildcard)', function (done) { | ||
it('fails to match bad request (wildcard)', (done) => { | ||
var router = new Call.Router(); | ||
const router = new Call.Router(); | ||
router.add({ method: 'get', path: '/{p*}' }); | ||
@@ -707,5 +709,5 @@ expect(router.route('get', '/%p').output.statusCode).to.equal(400); | ||
it('fails to match bad request (deep)', function (done) { | ||
it('fails to match bad request (deep)', (done) => { | ||
var router = new Call.Router(); | ||
const router = new Call.Router(); | ||
router.add({ method: 'get', path: '/a/{p}' }); | ||
@@ -717,10 +719,10 @@ expect(router.route('get', '/a/%p').output.statusCode).to.equal(400); | ||
describe('normalize()', function () { | ||
describe('normalize()', () => { | ||
it('normalizes a path', function (done) { | ||
it('normalizes a path', (done) => { | ||
var rawPath = '/%0%1%2%3%4%5%6%7%8%9%a%b%c%d%e%f%10%11%12%13%14%15%16%17%18%19%1a%1b%1c%1d%1e%1f%20%21%22%23%24%25%26%27%28%29%2a%2b%2c%2d%2e%2f%30%31%32%33%34%35%36%37%38%39%3a%3b%3c%3d%3e%3f%40%41%42%43%44%45%46%47%48%49%4a%4b%4c%4d%4e%4f%50%51%52%53%54%55%56%57%58%59%5a%5b%5c%5d%5e%5f%60%61%62%63%64%65%66%67%68%69%6a%6b%6c%6d%6e%6f%70%71%72%73%74%75%76%77%78%79%7a%7b%7c%7d%7e%7f%80%81%82%83%84%85%86%87%88%89%8a%8b%8c%8d%8e%8f%90%91%92%93%94%95%96%97%98%99%9a%9b%9c%9d%9e%9f%a0%a1%a2%a3%a4%a5%a6%a7%a8%a9%aa%ab%ac%ad%ae%af%b0%b1%b2%b3%b4%b5%b6%b7%b8%b9%ba%bb%bc%bd%be%bf%c0%c1%c2%c3%c4%c5%c6%c7%c8%c9%ca%cb%cc%cd%ce%cf%d0%d1%d2%d3%d4%d5%d6%d7%d8%d9%da%db%dc%dd%de%df%e0%e1%e2%e3%e4%e5%e6%e7%e8%e9%ea%eb%ec%ed%ee%ef%f0%f1%f2%f3%f4%f5%f6%f7%f8%f9%fa%fb%fc%fd%fe%ff%0%1%2%3%4%5%6%7%8%9%A%B%C%D%E%F%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D%1E%1F%20%21%22%23%24%25%26%27%28%29%2A%2B%2C%2D%2E%2F%30%31%32%33%34%35%36%37%38%39%3A%3B%3C%3D%3E%3F%40%41%42%43%44%45%46%47%48%49%4A%4B%4C%4D%4E%4F%50%51%52%53%54%55%56%57%58%59%5A%5B%5C%5D%5E%5F%60%61%62%63%64%65%66%67%68%69%6A%6B%6C%6D%6E%6F%70%71%72%73%74%75%76%77%78%79%7A%7B%7C%7D%7E%7F%80%81%82%83%84%85%86%87%88%89%8A%8B%8C%8D%8E%8F%90%91%92%93%94%95%96%97%98%99%9A%9B%9C%9D%9E%9F%A0%A1%A2%A3%A4%A5%A6%A7%A8%A9%AA%AB%AC%AD%AE%AF%B0%B1%B2%B3%B4%B5%B6%B7%B8%B9%BA%BB%BC%BD%BE%BF%C0%C1%C2%C3%C4%C5%C6%C7%C8%C9%CA%CB%CC%CD%CE%CF%D0%D1%D2%D3%D4%D5%D6%D7%D8%D9%DA%DB%DC%DD%DE%DF%E0%E1%E2%E3%E4%E5%E6%E7%E8%E9%EA%EB%EC%ED%EE%EF%F0%F1%F2%F3%F4%F5%F6%F7%F8%F9%FA%FB%FC%FD%FE%FF'; | ||
var normPath = '/%0%1%2%3%4%5%6%7%8%9%a%b%c%d%e%f%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D%1E%1F%20!%22%23$%25&\'()*+,-.%2F0123456789:;%3C=%3E%3F@ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D~%7F%80%81%82%83%84%85%86%87%88%89%8A%8B%8C%8D%8E%8F%90%91%92%93%94%95%96%97%98%99%9A%9B%9C%9D%9E%9F%A0%A1%A2%A3%A4%A5%A6%A7%A8%A9%AA%AB%AC%AD%AE%AF%B0%B1%B2%B3%B4%B5%B6%B7%B8%B9%BA%BB%BC%BD%BE%BF%C0%C1%C2%C3%C4%C5%C6%C7%C8%C9%CA%CB%CC%CD%CE%CF%D0%D1%D2%D3%D4%D5%D6%D7%D8%D9%DA%DB%DC%DD%DE%DF%E0%E1%E2%E3%E4%E5%E6%E7%E8%E9%EA%EB%EC%ED%EE%EF%F0%F1%F2%F3%F4%F5%F6%F7%F8%F9%FA%FB%FC%FD%FE%FF%0%1%2%3%4%5%6%7%8%9%A%B%C%D%E%F%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D%1E%1F%20!%22%23$%25&\'()*+,-.%2F0123456789:;%3C=%3E%3F@ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D~%7F%80%81%82%83%84%85%86%87%88%89%8A%8B%8C%8D%8E%8F%90%91%92%93%94%95%96%97%98%99%9A%9B%9C%9D%9E%9F%A0%A1%A2%A3%A4%A5%A6%A7%A8%A9%AA%AB%AC%AD%AE%AF%B0%B1%B2%B3%B4%B5%B6%B7%B8%B9%BA%BB%BC%BD%BE%BF%C0%C1%C2%C3%C4%C5%C6%C7%C8%C9%CA%CB%CC%CD%CE%CF%D0%D1%D2%D3%D4%D5%D6%D7%D8%D9%DA%DB%DC%DD%DE%DF%E0%E1%E2%E3%E4%E5%E6%E7%E8%E9%EA%EB%EC%ED%EE%EF%F0%F1%F2%F3%F4%F5%F6%F7%F8%F9%FA%FB%FC%FD%FE%FF'; | ||
const rawPath = '/%0%1%2%3%4%5%6%7%8%9%a%b%c%d%e%f%10%11%12%13%14%15%16%17%18%19%1a%1b%1c%1d%1e%1f%20%21%22%23%24%25%26%27%28%29%2a%2b%2c%2d%2e%2f%30%31%32%33%34%35%36%37%38%39%3a%3b%3c%3d%3e%3f%40%41%42%43%44%45%46%47%48%49%4a%4b%4c%4d%4e%4f%50%51%52%53%54%55%56%57%58%59%5a%5b%5c%5d%5e%5f%60%61%62%63%64%65%66%67%68%69%6a%6b%6c%6d%6e%6f%70%71%72%73%74%75%76%77%78%79%7a%7b%7c%7d%7e%7f%80%81%82%83%84%85%86%87%88%89%8a%8b%8c%8d%8e%8f%90%91%92%93%94%95%96%97%98%99%9a%9b%9c%9d%9e%9f%a0%a1%a2%a3%a4%a5%a6%a7%a8%a9%aa%ab%ac%ad%ae%af%b0%b1%b2%b3%b4%b5%b6%b7%b8%b9%ba%bb%bc%bd%be%bf%c0%c1%c2%c3%c4%c5%c6%c7%c8%c9%ca%cb%cc%cd%ce%cf%d0%d1%d2%d3%d4%d5%d6%d7%d8%d9%da%db%dc%dd%de%df%e0%e1%e2%e3%e4%e5%e6%e7%e8%e9%ea%eb%ec%ed%ee%ef%f0%f1%f2%f3%f4%f5%f6%f7%f8%f9%fa%fb%fc%fd%fe%ff%0%1%2%3%4%5%6%7%8%9%A%B%C%D%E%F%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D%1E%1F%20%21%22%23%24%25%26%27%28%29%2A%2B%2C%2D%2E%2F%30%31%32%33%34%35%36%37%38%39%3A%3B%3C%3D%3E%3F%40%41%42%43%44%45%46%47%48%49%4A%4B%4C%4D%4E%4F%50%51%52%53%54%55%56%57%58%59%5A%5B%5C%5D%5E%5F%60%61%62%63%64%65%66%67%68%69%6A%6B%6C%6D%6E%6F%70%71%72%73%74%75%76%77%78%79%7A%7B%7C%7D%7E%7F%80%81%82%83%84%85%86%87%88%89%8A%8B%8C%8D%8E%8F%90%91%92%93%94%95%96%97%98%99%9A%9B%9C%9D%9E%9F%A0%A1%A2%A3%A4%A5%A6%A7%A8%A9%AA%AB%AC%AD%AE%AF%B0%B1%B2%B3%B4%B5%B6%B7%B8%B9%BA%BB%BC%BD%BE%BF%C0%C1%C2%C3%C4%C5%C6%C7%C8%C9%CA%CB%CC%CD%CE%CF%D0%D1%D2%D3%D4%D5%D6%D7%D8%D9%DA%DB%DC%DD%DE%DF%E0%E1%E2%E3%E4%E5%E6%E7%E8%E9%EA%EB%EC%ED%EE%EF%F0%F1%F2%F3%F4%F5%F6%F7%F8%F9%FA%FB%FC%FD%FE%FF'; | ||
const normPath = '/%0%1%2%3%4%5%6%7%8%9%a%b%c%d%e%f%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D%1E%1F%20!%22%23$%25&\'()*+,-.%2F0123456789:;%3C=%3E%3F@ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D~%7F%80%81%82%83%84%85%86%87%88%89%8A%8B%8C%8D%8E%8F%90%91%92%93%94%95%96%97%98%99%9A%9B%9C%9D%9E%9F%A0%A1%A2%A3%A4%A5%A6%A7%A8%A9%AA%AB%AC%AD%AE%AF%B0%B1%B2%B3%B4%B5%B6%B7%B8%B9%BA%BB%BC%BD%BE%BF%C0%C1%C2%C3%C4%C5%C6%C7%C8%C9%CA%CB%CC%CD%CE%CF%D0%D1%D2%D3%D4%D5%D6%D7%D8%D9%DA%DB%DC%DD%DE%DF%E0%E1%E2%E3%E4%E5%E6%E7%E8%E9%EA%EB%EC%ED%EE%EF%F0%F1%F2%F3%F4%F5%F6%F7%F8%F9%FA%FB%FC%FD%FE%FF%0%1%2%3%4%5%6%7%8%9%A%B%C%D%E%F%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D%1E%1F%20!%22%23$%25&\'()*+,-.%2F0123456789:;%3C=%3E%3F@ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D~%7F%80%81%82%83%84%85%86%87%88%89%8A%8B%8C%8D%8E%8F%90%91%92%93%94%95%96%97%98%99%9A%9B%9C%9D%9E%9F%A0%A1%A2%A3%A4%A5%A6%A7%A8%A9%AA%AB%AC%AD%AE%AF%B0%B1%B2%B3%B4%B5%B6%B7%B8%B9%BA%BB%BC%BD%BE%BF%C0%C1%C2%C3%C4%C5%C6%C7%C8%C9%CA%CB%CC%CD%CE%CF%D0%D1%D2%D3%D4%D5%D6%D7%D8%D9%DA%DB%DC%DD%DE%DF%E0%E1%E2%E3%E4%E5%E6%E7%E8%E9%EA%EB%EC%ED%EE%EF%F0%F1%F2%F3%F4%F5%F6%F7%F8%F9%FA%FB%FC%FD%FE%FF'; | ||
var router = new Call.Router(); | ||
const router = new Call.Router(); | ||
expect(router.normalize(rawPath)).to.equal(normPath); | ||
@@ -730,5 +732,5 @@ done(); | ||
it('returns empty path on empty', function (done) { | ||
it('returns empty path on empty', (done) => { | ||
var router = new Call.Router(); | ||
const router = new Call.Router(); | ||
expect(router.normalize('')).to.equal(''); | ||
@@ -739,7 +741,7 @@ done(); | ||
describe('analyze()', function () { | ||
describe('analyze()', () => { | ||
it('generates fingerprints', function (done) { | ||
it('generates fingerprints', (done) => { | ||
var paths = { | ||
const paths = { | ||
'/': '/', | ||
@@ -771,5 +773,5 @@ '/path': '/path', | ||
var router = new Call.Router({ isCaseSensitive: true }); | ||
var keys = Object.keys(paths); | ||
for (var i = 0, il = keys.length; i < il; ++i) { | ||
const router = new Call.Router({ isCaseSensitive: true }); | ||
const keys = Object.keys(paths); | ||
for (let i = 0; i < keys.length; ++i) { | ||
expect(router.analyze(keys[i]).fingerprint).to.equal(paths[keys[i]]); | ||
@@ -782,11 +784,11 @@ } | ||
describe('table()', function () { | ||
describe('table()', () => { | ||
it('returns an array of the current routes', function (done) { | ||
it('returns an array of the current routes', (done) => { | ||
var router = new Call.Router(); | ||
const router = new Call.Router(); | ||
router.add({ path: '/test/', method: 'get' }); | ||
router.add({ path: '/test/{p}/end', method: 'get' }); | ||
var routes = router.table(); | ||
const routes = router.table(); | ||
@@ -798,5 +800,5 @@ expect(routes.length).to.equal(2); | ||
it('combines global and vhost routes', function (done) { | ||
it('combines global and vhost routes', (done) => { | ||
var router = new Call.Router(); | ||
const router = new Call.Router(); | ||
@@ -808,3 +810,3 @@ router.add({ path: '/test/', method: 'get' }); | ||
var routes = router.table(); | ||
const routes = router.table(); | ||
@@ -815,5 +817,5 @@ expect(routes.length).to.equal(4); | ||
it('combines global and vhost routes and filters based on host', function (done) { | ||
it('combines global and vhost routes and filters based on host', (done) => { | ||
var router = new Call.Router(); | ||
const router = new Call.Router(); | ||
@@ -825,3 +827,3 @@ router.add({ path: '/test/', method: 'get' }); | ||
var routes = router.table('one.example.com'); | ||
const routes = router.table('one.example.com'); | ||
@@ -832,5 +834,5 @@ expect(routes.length).to.equal(3); | ||
it('accepts a list of hosts', function (done) { | ||
it('accepts a list of hosts', (done) => { | ||
var router = new Call.Router(); | ||
const router = new Call.Router(); | ||
@@ -842,3 +844,3 @@ router.add({ path: '/test/', method: 'get' }); | ||
var routes = router.table(['one.example.com', 'two.example.com']); | ||
const routes = router.table(['one.example.com', 'two.example.com']); | ||
@@ -849,5 +851,5 @@ expect(routes.length).to.equal(4); | ||
it('ignores unknown host', function (done) { | ||
it('ignores unknown host', (done) => { | ||
var router = new Call.Router(); | ||
const router = new Call.Router(); | ||
@@ -859,3 +861,3 @@ router.add({ path: '/test/', method: 'get' }); | ||
var routes = router.table('three.example.com'); | ||
const routes = router.table('three.example.com'); | ||
@@ -862,0 +864,0 @@ expect(routes.length).to.equal(2); |
@@ -0,6 +1,8 @@ | ||
'use strict'; | ||
// Load modules | ||
var Code = require('code'); | ||
var Lab = require('lab'); | ||
var Regex = require('../lib/regex'); | ||
const Code = require('code'); | ||
const Lab = require('lab'); | ||
const Regex = require('../lib/regex'); | ||
@@ -10,3 +12,3 @@ | ||
var internals = {}; | ||
const internals = {}; | ||
@@ -16,89 +18,86 @@ | ||
var lab = exports.lab = Lab.script(); | ||
var describe = lab.describe; | ||
var it = lab.it; | ||
var expect = Code.expect; | ||
const lab = exports.lab = Lab.script(); | ||
const describe = lab.describe; | ||
const it = lab.it; | ||
const expect = Code.expect; | ||
describe('Call', function () { | ||
describe('Call', () => { | ||
describe('Regex', function () { | ||
describe('Regex', () => { | ||
var pathRegex = Regex.generate(); | ||
const pathRegex = Regex.generate(); | ||
describe('validatePath', function () { | ||
describe('validatePath', () => { | ||
var testPaths = function () { | ||
const paths = { | ||
'/': true, | ||
'/path': true, | ||
'/path/': true, | ||
'/path/to/somewhere': true, | ||
'/{param}': true, | ||
'/{param?}': true, | ||
'/{param*}': true, | ||
'/{param*5}': true, | ||
'/path/{param}': true, | ||
'/path/{param}/to': true, | ||
'/path/{param?}': true, | ||
'/path/{param}/to/{some}': true, | ||
'/path/{param}/to/{some?}': true, | ||
'/path/{param*2}/to': true, | ||
'/path/{param*27}/to': true, | ||
'/path/{param*2}': true, | ||
'/path/{param*27}': true, | ||
'/%20path/': true, | ||
'path': false, | ||
'/%path/': false, | ||
'/path/{param*}/to': false, | ||
'/path/{param*0}/to': false, | ||
'/path/{param*0}': false, | ||
'/path/{param*01}/to': false, | ||
'/path/{param*01}': false, | ||
'/{param?}/something': false, | ||
'/{param*03}': false, | ||
'/{param*3?}': false, | ||
'/{param*?}': false, | ||
'/{param*}/': false, | ||
'/a{p}': true, | ||
'/{p}b': true, | ||
'/a{p}b': true, | ||
'/d/a{p}': true, | ||
'/d/{p}b': true, | ||
'/d/a{p}b': true, | ||
'/a{p}/d': true, | ||
'/{p}b/d': true, | ||
'/a{p}b/d': true, | ||
'/d/a{p}/e': true, | ||
'/d/{p}b/e': true, | ||
'/d/a{p}b/e': true, | ||
'/a{p}.{x}': true, | ||
'/{p}{x}': false, | ||
'/a{p}{x}': false, | ||
'/a{p}{x}b': false, | ||
'/{p}{x}b': false, | ||
'/{p?}{x}b': false, | ||
'/{a}b{c?}d{e}': true, | ||
'/a{p?}': true, | ||
'/{p*}d': false, | ||
'/a{p*3}': false | ||
}; | ||
var paths = { | ||
'/': true, | ||
'/path': true, | ||
'/path/': true, | ||
'/path/to/somewhere': true, | ||
'/{param}': true, | ||
'/{param?}': true, | ||
'/{param*}': true, | ||
'/{param*5}': true, | ||
'/path/{param}': true, | ||
'/path/{param}/to': true, | ||
'/path/{param?}': true, | ||
'/path/{param}/to/{some}': true, | ||
'/path/{param}/to/{some?}': true, | ||
'/path/{param*2}/to': true, | ||
'/path/{param*27}/to': true, | ||
'/path/{param*2}': true, | ||
'/path/{param*27}': true, | ||
'/%20path/': true, | ||
'path': false, | ||
'/%path/': false, | ||
'/path/{param*}/to': false, | ||
'/path/{param*0}/to': false, | ||
'/path/{param*0}': false, | ||
'/path/{param*01}/to': false, | ||
'/path/{param*01}': false, | ||
'/{param?}/something': false, | ||
'/{param*03}': false, | ||
'/{param*3?}': false, | ||
'/{param*?}': false, | ||
'/{param*}/': false, | ||
'/a{p}': true, | ||
'/{p}b': true, | ||
'/a{p}b': true, | ||
'/d/a{p}': true, | ||
'/d/{p}b': true, | ||
'/d/a{p}b': true, | ||
'/a{p}/d': true, | ||
'/{p}b/d': true, | ||
'/a{p}b/d': true, | ||
'/d/a{p}/e': true, | ||
'/d/{p}b/e': true, | ||
'/d/a{p}b/e': true, | ||
'/a{p}.{x}': true, | ||
'/{p}{x}': false, | ||
'/a{p}{x}': false, | ||
'/a{p}{x}b': false, | ||
'/{p}{x}b': false, | ||
'/{p?}{x}b': false, | ||
'/{a}b{c?}d{e}': true, | ||
'/a{p?}': true, | ||
'/{p*}d': false, | ||
'/a{p*3}': false | ||
}; | ||
const test = function (path, isValid) { | ||
var test = function (path, isValid) { | ||
it('validates the path \'' + path + '\' as ' + (isValid ? 'well-formed' : 'malformed'), (done) => { | ||
it('validates the path \'' + path + '\' as ' + (isValid ? 'well-formed' : 'malformed'), function (done) { | ||
expect(!!(path.match(pathRegex.validatePath))).to.equal(isValid); | ||
done(); | ||
}); | ||
}; | ||
expect(!!(path.match(pathRegex.validatePath))).to.equal(isValid); | ||
done(); | ||
}); | ||
}; | ||
var keys = Object.keys(paths); | ||
for (var i = 0, il = keys.length; i < il; ++i) { | ||
test(keys[i], paths[keys[i]]); | ||
} | ||
}(); | ||
const keys = Object.keys(paths); | ||
for (let i = 0; i < keys.length; ++i) { | ||
test(keys[i], paths[keys[i]]); | ||
} | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
53753
1227
+ Addedboom@3.2.2(transitive)
+ Addedhoek@3.0.44.3.1(transitive)
- Removedboom@2.10.1(transitive)
- Removedhoek@2.16.3(transitive)
Updatedboom@3.x.x
Updatedhoek@3.x.x