Comparing version
@@ -12,4 +12,5 @@ "use strict"; | ||
ROUTE_MATCH = /<(\w+)>/ig, | ||
PATTERN_CAPTURE_REGEX = /\(((\?P?<(\w+)>)((:?(\(([^\/]+)\)))?|([^\)]+))|([^\)]+))\)/g, | ||
IS_NAMED = /\(\?P?<(\w+)>([^\)]+)\)/, | ||
PATTERN_CAPTURE_REGEX = /\(\??P?(<(\w+)>)?([^\)]+\)?)\)?\)/g, | ||
IS_NAMED = /<(\w+)>/, | ||
IS_GROUP = /^\(([^\)]+)\)$/, | ||
RouteRule; | ||
@@ -43,2 +44,3 @@ /** | ||
if (!config.pattern) { | ||
@@ -75,6 +77,8 @@ throw new error.HttpError(500, config, 'RouteRule: rule object must have an pattern property'); | ||
if (Array.isArray(matches) && matches.length) { | ||
matches.forEach(function (item) { | ||
var esc, nPattern; | ||
name = item[1]; | ||
nPattern = Type.isString(item[2]) ? item[2] : '[^\/]+'; | ||
nPattern = Type.isString(item[2]) ? item[2] : '([^\/]+)'; | ||
esc = { | ||
@@ -85,2 +89,3 @@ key: '<' + name + '>', | ||
escapePattern.push(esc); | ||
if (this.find(this.routeParams, name)) { | ||
@@ -91,3 +96,3 @@ escapeRule.push(esc); | ||
key: name, | ||
value: nPattern === '[^\/]+' ? '' : core.createRegex('^' + nPattern + '$') | ||
value: nPattern === '([^\/]+)' ? '' : core.createRegex('^' + nPattern + '$') | ||
}); | ||
@@ -315,2 +320,3 @@ } | ||
var matches = core.match(PATTERN_CAPTURE_REGEX, re), newRegex = re; | ||
if (matches.length) { | ||
@@ -320,9 +326,18 @@ matches = matches.map(this.toObject); | ||
var index = Object.keys(item).length - 3; | ||
item.isNamed = IS_NAMED.test(item[0]); | ||
item.isNamed = IS_NAMED.test(item[1]); | ||
if (item.isNamed) { | ||
item.pattern = '(' + item[index] + ')'; | ||
item.key = item[3]; | ||
if (IS_GROUP.test(item[index])) { | ||
item.pattern = item[index]; | ||
} else { | ||
item.pattern = '(' + item[index] + ')'; | ||
} | ||
item.key = item[2]; | ||
newRegex = newRegex.replace(item[0], item.pattern); | ||
} else { | ||
item.pattern = item[0]; | ||
if (IS_GROUP.test(item[index])) { | ||
item.pattern = item[index]; | ||
} else { | ||
item.pattern = '(' + item[index] + ')'; | ||
} | ||
item.key = null; | ||
@@ -354,3 +369,2 @@ } | ||
rgx = this.toRegex(rgx); | ||
} | ||
@@ -411,3 +425,3 @@ if (Type.isObject(rgx) && Type.isRegExp(rgx.regex)) { | ||
str = str.trim(); | ||
if (strip) { | ||
if (strip && str !== strip) { | ||
str = str.replace(core.createRegex('^' + strip), ''); | ||
@@ -414,0 +428,0 @@ str = str.replace(core.createRegex(strip + '$'), ''); |
@@ -5,3 +5,3 @@ { | ||
"description": "Powerful lightweight mvc framework for nodejs", | ||
"version": "0.1.0-beta-45", | ||
"version": "0.1.0-beta-46", | ||
"dependencies" : { | ||
@@ -8,0 +8,0 @@ "mongoose": "3.8.x", |
128527
0.28%4106
0.22%