From 87da9f3d8a9970db40bb7b6161451ce1a02ec4f3 Mon Sep 17 00:00:00 2001 From: Matthew Taylor Date: Thu, 18 May 2017 13:57:49 -0400 Subject: [PATCH] Use regex in express patterns to limit scope This fixes https://github.com/LLK/scratchr2/issues/3798 by using regex in expressjs patterns, and then also parsing those regex patterns for fastly, such that we can limit the scope of the regex created for a specific view --- bin/lib/fastly-config-methods.js | 3 ++- src/routes.json | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/bin/lib/fastly-config-methods.js b/bin/lib/fastly-config-methods.js index f20091103..3a3d7581c 100644 --- a/bin/lib/fastly-config-methods.js +++ b/bin/lib/fastly-config-methods.js @@ -37,7 +37,8 @@ var FastlyConfigMethods = { * all :arguments become .+? */ expressPatternToRegex: function (pattern) { - return pattern.replace(/(:[^/]+)/gi, '.+?'); + pattern = pattern.replace(/(:\w+)(\([^\)]+\))/gi, '$2'); + return pattern.replace(/(:\w+)/gi, '.+?'); }, /* diff --git a/src/routes.json b/src/routes.json index ab771a933..b0ae23107 100644 --- a/src/routes.json +++ b/src/routes.json @@ -127,7 +127,7 @@ }, { "name": "explore", - "pattern": "^/explore/:projects/:all/?$", + "pattern": "^/explore/:projects(projects|studios)/:all/?$", "routeAlias": "/explore(?!/ajax)", "view": "explore/explore", "title": "Explore"