find-my-way
Advanced tools
Comparing version 1.10.3 to 1.10.4
46
index.js
@@ -92,3 +92,3 @@ 'use strict' | ||
if (isRegex) { | ||
i = path.indexOf(')', i) + 1 | ||
i = getClosingParenthensePosition(path, i) + 1 | ||
break | ||
@@ -279,3 +279,2 @@ } else if (path.charCodeAt(i) !== 45) { | ||
var i = 0 | ||
var isStatic = true | ||
@@ -314,3 +313,3 @@ while (true) { | ||
if ((isStatic === true && len > 0) || len === prefixLen) { | ||
if (len === prefixLen) { | ||
path = path.slice(len) | ||
@@ -320,3 +319,3 @@ pathLen = path.length | ||
var node = currentNode.find(path[0], method) | ||
var node = currentNode.find(path, method) | ||
if (node === null) { | ||
@@ -348,4 +347,2 @@ node = currentNode.parametricBrother | ||
isStatic = false | ||
// if exist, save the wildcard child | ||
@@ -515,1 +512,38 @@ if (currentNode.wildcardChild !== null) { | ||
} | ||
/** | ||
* Returns the position of the last closing parenthese of the regexp expression. | ||
* | ||
* @param {String} path | ||
* @param {Number} idx | ||
* @returns {Number} | ||
* @throws {TypeError} when a closing parenthese is missing | ||
* @private | ||
*/ | ||
function getClosingParenthensePosition (path, idx) { | ||
// `path.indexOf()` will always return the first position of the closing parenthese, | ||
// but it's inefficient for grouped or wrong regexp expressions. | ||
// see issues #62 and #63 for more info | ||
var parentheses = 1 | ||
while (idx < path.length) { | ||
idx++ | ||
// ignore skipped chars | ||
if (path[idx] === '\\') { | ||
idx++ | ||
continue | ||
} | ||
if (path[idx] === ')') { | ||
parentheses-- | ||
} else if (path[idx] === '(') { | ||
parentheses++ | ||
} | ||
if (!parentheses) return idx | ||
} | ||
throw new TypeError('Invalid regexp expression in "' + path + '"') | ||
} |
12
node.js
@@ -65,10 +65,10 @@ 'use strict' | ||
Node.prototype.find = function (label, method) { | ||
Node.prototype.find = function (path, method) { | ||
for (var i = 0; i < this.numberOfChildren; i++) { | ||
var child = this.children[i] | ||
if (child.numberOfChildren !== 0 || child.handlers[method] !== null) { | ||
if (child.label === label && child.kind === 0) { | ||
return child | ||
} | ||
if (child.kind !== 0) return child | ||
if ( | ||
(child.numberOfChildren !== 0 || child.handlers[method] !== null) && | ||
(child.kind !== 0 || path.slice(0, child.prefix.length) === child.prefix) | ||
) { | ||
return child | ||
} | ||
@@ -75,0 +75,0 @@ } |
{ | ||
"name": "find-my-way", | ||
"version": "1.10.3", | ||
"version": "1.10.4", | ||
"description": "Crazy fast http radix based router", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
109353
27
3232