find-my-way
Advanced tools
Comparing version 4.2.0 to 4.3.0
29
index.js
@@ -8,2 +8,3 @@ 'use strict' | ||
'-': 45 | ||
'.': 46 | ||
'/': 47 | ||
@@ -156,3 +157,3 @@ ':': 58 | ||
break | ||
} else if (path.charCodeAt(i) !== 45) { | ||
} else if (path.charCodeAt(i) !== 45 && path.charCodeAt(i) !== 46) { | ||
i++ | ||
@@ -420,3 +421,3 @@ } else { | ||
if (node === null) { | ||
return this._getWildcardNode(wildcardNode, originalPath, pathLenWildcard) | ||
return this._getWildcardNode(wildcardNode, originalPath, pathLenWildcard, derivedConstraints, params) | ||
} | ||
@@ -453,3 +454,3 @@ | ||
if (len !== prefixLen) { | ||
return this._getWildcardNode(wildcardNode, originalPath, pathLenWildcard) | ||
return this._getWildcardNode(wildcardNode, originalPath, pathLenWildcard, derivedConstraints, params) | ||
} | ||
@@ -526,3 +527,3 @@ | ||
} else { | ||
while (i < pathLen && path.charCodeAt(i) !== 47 && path.charCodeAt(i) !== 45) i++ | ||
while (i < pathLen && path.charCodeAt(i) !== 47 && path.charCodeAt(i) !== 45 && path.charCodeAt(i) !== 46) i++ | ||
if (i > maxParamLength) return null | ||
@@ -547,3 +548,3 @@ } | ||
Router.prototype._getWildcardNode = function (node, path, len) { | ||
Router.prototype._getWildcardNode = function (node, path, len, derivedConstraints, params) { | ||
if (node === null) return null | ||
@@ -556,7 +557,21 @@ var decoded = fastDecode(path.slice(-len)) | ||
} | ||
var handle = node.handlers[0] | ||
var handle = derivedConstraints !== undefined ? node.getMatchingHandler(derivedConstraints) : node.unconstrainedHandler | ||
if (handle !== null && handle !== undefined) { | ||
var paramsObj = {} | ||
if (handle.paramsLength > 0 && params !== null) { | ||
var paramNames = handle.params | ||
for (i = 0; i < handle.paramsLength; i++) { | ||
paramsObj[paramNames[i]] = params[i] | ||
} | ||
} | ||
// we must override params[*] to decoded | ||
paramsObj['*'] = decoded | ||
return { | ||
handler: handle.handler, | ||
params: { '*': decoded }, | ||
params: paramsObj, | ||
store: handle.store | ||
@@ -563,0 +578,0 @@ } |
{ | ||
"name": "find-my-way", | ||
"version": "4.2.0", | ||
"version": "4.3.0", | ||
"description": "Crazy fast http radix based router", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -23,3 +23,3 @@ 'use strict' | ||
test('Parametric route with fixed suffix', t => { | ||
t.plan(1) | ||
t.plan(2) | ||
const findMyWay = FindMyWay({ | ||
@@ -35,3 +35,8 @@ defaultRoute: (req, res) => { | ||
findMyWay.on('GET', '/b/:param.bar', function bloo (req, res, params) { | ||
t.equal(params.param, 'foo') | ||
}) | ||
findMyWay.lookup({ method: 'GET', url: '/a/foo-bar', headers: {} }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/b/foo.bar', headers: {} }, null) | ||
}) | ||
@@ -88,3 +93,3 @@ | ||
test('Multi parametric route / 1', t => { | ||
t.plan(2) | ||
t.plan(4) | ||
const findMyWay = FindMyWay({ | ||
@@ -101,7 +106,13 @@ defaultRoute: (req, res) => { | ||
findMyWay.on('GET', '/b/:p1.:p2', (req, res, params) => { | ||
t.equal(params.p1, 'foo') | ||
t.equal(params.p2, 'bar') | ||
}) | ||
findMyWay.lookup({ method: 'GET', url: '/a/foo-bar', headers: {} }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/b/foo.bar', headers: {} }, null) | ||
}) | ||
test('Multi parametric route / 2', t => { | ||
t.plan(2) | ||
t.plan(4) | ||
const findMyWay = FindMyWay({ | ||
@@ -118,7 +129,13 @@ defaultRoute: (req, res) => { | ||
findMyWay.on('GET', '/b/:p1.:p2', (req, res, params) => { | ||
t.equal(params.p1, 'foo') | ||
t.equal(params.p2, 'bar-baz') | ||
}) | ||
findMyWay.lookup({ method: 'GET', url: '/a/foo-bar-baz', headers: {} }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/b/foo.bar-baz', headers: {} }, null) | ||
}) | ||
test('Multi parametric route / 3', t => { | ||
t.plan(2) | ||
t.plan(4) | ||
const findMyWay = FindMyWay({ | ||
@@ -135,7 +152,13 @@ defaultRoute: (req, res) => { | ||
findMyWay.on('GET', '/b/:p_1.:$p', (req, res, params) => { | ||
t.equal(params.p_1, 'foo') | ||
t.equal(params.$p, 'bar') | ||
}) | ||
findMyWay.lookup({ method: 'GET', url: '/a/foo-bar', headers: {} }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/b/foo.bar', headers: {} }, null) | ||
}) | ||
test('Multi parametric route / 4', t => { | ||
t.plan(1) | ||
t.plan(2) | ||
const findMyWay = FindMyWay({ | ||
@@ -151,3 +174,8 @@ defaultRoute: (req, res) => { | ||
findMyWay.on('GET', '/b/:p1.:p2', (req, res, params) => { | ||
t.fail('Should not match this route') | ||
}) | ||
findMyWay.lookup({ method: 'GET', url: '/a/foo', headers: {} }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/b/foo', headers: {} }, null) | ||
}) | ||
@@ -172,3 +200,3 @@ | ||
test('Multi parametric route with regexp / 2', t => { | ||
t.plan(4) | ||
t.plan(8) | ||
const findMyWay = FindMyWay({ | ||
@@ -190,8 +218,21 @@ defaultRoute: (req, res) => { | ||
findMyWay.on('GET', '/b/:uuid(^[\\d-]{19}).:user(^\\w+)', (req, res, params) => { | ||
t.equal(params.uuid, '1111-2222-3333-4444') | ||
t.equal(params.user, 'foo') | ||
}) | ||
findMyWay.on('GET', '/b/:uuid(^[\\d-]{19}).:user(^\\w+)/account', (req, res, params) => { | ||
t.equal(params.uuid, '1111-2222-3333-4445') | ||
t.equal(params.user, 'bar') | ||
}) | ||
findMyWay.lookup({ method: 'GET', url: '/a/1111-2222-3333-4444-foo', headers: {} }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/a/1111-2222-3333-4445-bar/account', headers: {} }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/b/1111-2222-3333-4444.foo', headers: {} }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/b/1111-2222-3333-4445.bar/account', headers: {} }, null) | ||
}) | ||
test('Multi parametric route with fixed suffix', t => { | ||
t.plan(2) | ||
t.plan(4) | ||
const findMyWay = FindMyWay({ | ||
@@ -208,7 +249,13 @@ defaultRoute: (req, res) => { | ||
findMyWay.on('GET', '/b/:p1.:p2-baz', (req, res, params) => { | ||
t.equal(params.p1, 'foo') | ||
t.equal(params.p2, 'bar') | ||
}) | ||
findMyWay.lookup({ method: 'GET', url: '/a/foo-bar-baz', headers: {} }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/b/foo.bar-baz', headers: {} }, null) | ||
}) | ||
test('Multi parametric route with regexp and fixed suffix', t => { | ||
t.plan(2) | ||
t.plan(4) | ||
const findMyWay = FindMyWay({ | ||
@@ -225,7 +272,13 @@ defaultRoute: (req, res) => { | ||
findMyWay.on('GET', '/b/:p1(^\\w+).:p2(^\\w+)-kuux', (req, res, params) => { | ||
t.equal(params.p1, 'foo') | ||
t.equal(params.p2, 'barbaz') | ||
}) | ||
findMyWay.lookup({ method: 'GET', url: '/a/foo-barbaz-kuux', headers: {} }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/b/foo.barbaz-kuux', headers: {} }, null) | ||
}) | ||
test('Multi parametric route with wildcard', t => { | ||
t.plan(2) | ||
t.plan(4) | ||
const findMyWay = FindMyWay({ | ||
@@ -242,7 +295,13 @@ defaultRoute: (req, res) => { | ||
findMyWay.on('GET', '/b/:p1.:p2/*', (req, res, params) => { | ||
t.equal(params.p1, 'foo') | ||
t.equal(params.p2, 'bar') | ||
}) | ||
findMyWay.lookup({ method: 'GET', url: '/a/foo-bar/baz', headers: {} }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/b/foo.bar/baz', headers: {} }, null) | ||
}) | ||
test('Nested multi parametric route', t => { | ||
t.plan(3) | ||
t.plan(6) | ||
const findMyWay = FindMyWay({ | ||
@@ -260,7 +319,14 @@ defaultRoute: (req, res) => { | ||
findMyWay.on('GET', '/b/:p1.:p2/b/:p3', (req, res, params) => { | ||
t.equal(params.p1, 'foo') | ||
t.equal(params.p2, 'bar') | ||
t.equal(params.p3, 'baz') | ||
}) | ||
findMyWay.lookup({ method: 'GET', url: '/a/foo-bar/b/baz', headers: {} }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/b/foo.bar/b/baz', headers: {} }, null) | ||
}) | ||
test('Nested multi parametric route with regexp / 1', t => { | ||
t.plan(3) | ||
t.plan(6) | ||
const findMyWay = FindMyWay({ | ||
@@ -278,7 +344,14 @@ defaultRoute: (req, res) => { | ||
findMyWay.on('GET', '/b/:p1(^\\w{3}).:p2(^\\d+)/b/:p3', (req, res, params) => { | ||
t.equal(params.p1, 'foo') | ||
t.equal(params.p2, '42') | ||
t.equal(params.p3, 'bar') | ||
}) | ||
findMyWay.lookup({ method: 'GET', url: '/a/foo-42/b/bar', headers: {} }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/b/foo.42/b/bar', headers: {} }, null) | ||
}) | ||
test('Nested multi parametric route with regexp / 2', t => { | ||
t.plan(3) | ||
t.plan(6) | ||
const findMyWay = FindMyWay({ | ||
@@ -296,3 +369,10 @@ defaultRoute: (req, res) => { | ||
findMyWay.on('GET', '/b/:p1(^\\w{3}).:p2/b/:p3', (req, res, params) => { | ||
t.equal(params.p1, 'foo') | ||
t.equal(params.p2, '42') | ||
t.equal(params.p3, 'bar') | ||
}) | ||
findMyWay.lookup({ method: 'GET', url: '/a/foo-42/b/bar', headers: {} }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/b/foo.42/b/bar', headers: {} }, null) | ||
}) |
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
242563
58
6106