strapi-middleware-cache icon indicating copy to clipboard operation
strapi-middleware-cache copied to clipboard

Faulty logic in param matching for getRouteRegExp

Open joacimastrom opened this issue 3 years ago • 2 comments

The matching of params when creating the regex is breaking since params extracted from the route will have format [":param1", ":param2"] while the ones added wont have the : since they are likely used as:

getCacheConfRegExp(cacheConf, {
  param1,
  param2,
});

Even if you explicitly name the params

getCacheConfRegExp(cacheConf, {
  ":param1": param1,
  ":param2": param2,
});

the pattern-replace will fail in the loop a few lines down since it then tries to match ::param1 which doesn't exist in the route

pattern = pattern.replace(`:${paramName}`, params[paramName]);

joacimastrom avatar Oct 25 '21 07:10 joacimastrom

Opened a PR with a quick fix for this: https://github.com/patrixr/strapi-middleware-cache/pull/70

Ought to be non-breaking?

joacimastrom avatar Oct 25 '21 11:10 joacimastrom

@patrixr have you had the chance to take a look at this?

joacimastrom avatar Oct 26 '21 07:10 joacimastrom