X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Frouter%2Findex.js;fp=lib%2Frouter%2Findex.js;h=f0d2d945a53909c327ab1661c54e83e9a6cfe097;hb=1296167385b38ca226f17c3a87ac2135d53c769b;hp=a13ac47d62f083e588d047f7d556f7502f4b91e4;hpb=c19f9a34ec7ae311e025118e51705842e31e7066;p=squeep-api-dingus diff --git a/lib/router/index.js b/lib/router/index.js index a13ac47..f0d2d94 100644 --- a/lib/router/index.js +++ b/lib/router/index.js @@ -61,17 +61,37 @@ class Router { _pathToRoutePath(rawPath) { const routePath = rawPath .split('/') - .map((p) => p.startsWith(this.paramPrefix) ? new PathParameter(p.slice(this.paramPrefix.length)) : p); + .map((p) => this._pathPartMunge(p)); + if (this.ignoreTrailingSlash && routePath[routePath.length - 1] === '') { routePath.pop(); } + routePath[kPathMethods] = {}; Object.freeze(routePath); return routePath; } + /* + * Convert a path part string to parameter if needed. + * Remove escape from an escaped parameter. + * @param {String} part + * @returns {PathParameter|String} + * @private + */ + _pathPartMunge(part) { + if (part.startsWith(this.paramPrefix)) { + return new PathParameter(part.slice(this.paramPrefix.length)); + } + if (part.startsWith('\\' + this.paramPrefix)) { + return part.slice(1); + } + return part; + } + + /** * Compare checkPath to fixedPath, no param substitution, params must match. * @param {Router~RoutePath} routePath