putyourlightson / craft-blitz

Intelligent static page caching for creating lightning-fast sites with Craft CMS.
https://putyourlightson.com/plugins/blitz
Other
149 stars 36 forks source link

URI not stripping leading slash when accessed via direct web request #29

Closed seanrabey closed 5 years ago

seanrabey commented 6 years ago

We've setup our caching system and have found that blacklist rules like '^pages' work properly when using the warmer, but when accessing from the website, the cache tool does not strip the leading slash from the URI like it does in the warmer. See: /Blitz.php line 61 vs /src/services/CacheService.php line 385

putyourlightson commented 5 years ago

Thanks for reporting this, we’ll look into fixing it for the next release.

putyourlightson commented 5 years ago

Can you please explain how you are testing that this is causing issues? It is not exactly clear to me how the leading slash could be a problem as it is trimmed before being tested in _matchUriPattern here: https://github.com/putyourlightson/craft-blitz/blob/1.5.4/src/services/CacheService.php#L465

seanrabey commented 5 years ago

Thanks for looking at this. Here is the scenario: If we used a blacklist rule of ^pages and we are looking at a URI of /pages/about When accessing this page directly from the website, say https://example.com/pages/about the init() function of src/Blitz.php will run and produce a $uri of '/pages/about' which then eventually makes it's way to _matchUriPattern(), but the leading '/' is not stripped from the $uri, so the pattern match of ^pages does not match.

When the same URI is generated from the warmer, /src/services/CacheService.php line 385 does trim the URI to be 'pages/about' and the pattern '^pages' does correctly work.

I think the key takeaway would either be to trim the $uri on /Blitz.php line 61 or always trim both the pattern and the uri on /src/services/CacheService.php line 465

Hope that helps. Thanks again for looking at this

putyourlightson commented 5 years ago

Thanks for the detailed explanation, we'll have a fix for this later this week.

putyourlightson commented 5 years ago

Fixed in https://github.com/putyourlightson/craft-blitz/commit/ce8872b1b61326c8742cbb03491f67e8a9cdfc83