From 91e3bf5fb4c76c46e57b8a7f2c50b627a95f2f81 Mon Sep 17 00:00:00 2001 From: bencroker Date: Wed, 13 Nov 2024 11:13:32 +0100 Subject: [PATCH] Use regexp to determin uppercase letters --- CHANGELOG.md | 6 ++++++ composer.json | 2 +- src/services/CacheRequestService.php | 16 +++++++--------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12345410..eefcae0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Release Notes for Blitz +## 5.9.5 - 2024-11-13 + +### Fixed + +- Fixed a bug in which URIs could be incorrectly determined to contain uppercase letters during cache generation. + ## 5.9.4 - 2024-11-13 ### Fixed diff --git a/composer.json b/composer.json index 0bcd9012..a32600b2 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "putyourlightson/craft-blitz", "description": "Intelligent static page caching for creating lightning-fast sites.", - "version": "5.9.4", + "version": "5.9.5", "type": "craft-plugin", "homepage": "https://putyourlightson.com/plugins/blitz", "license": "proprietary", diff --git a/src/services/CacheRequestService.php b/src/services/CacheRequestService.php index e96a3c9c..7c13f9e1 100755 --- a/src/services/CacheRequestService.php +++ b/src/services/CacheRequestService.php @@ -196,9 +196,7 @@ public function getIsCacheableSiteUri(?SiteUriModel $siteUri): bool return false; } - $uri = mb_strtolower($siteUri->uri); - - if (Blitz::$plugin->settings->onlyCacheLowercaseUris && $uri !== $siteUri->uri) { + if (Blitz::$plugin->settings->onlyCacheLowercaseUris && preg_match('/\p{Lu}/u', $siteUri->uri)) { Blitz::$plugin->debug('Page not cached because the URI contains uppercase characters.', [], $siteUri->uri); return false; @@ -206,17 +204,17 @@ public function getIsCacheableSiteUri(?SiteUriModel $siteUri): bool // Ignore URIs that are longer than the max URI length $max = Blitz::$plugin->settings->maxUriLength; - if (strlen($uri) > $max) { - Blitz::$plugin->debug('Page not cached because it exceeds the max URI length of {max}.', ['max' => $max], $uri); + if (strlen($siteUri->uri) > $max) { + Blitz::$plugin->debug('Page not cached because it exceeds the max URI length of {max}.', ['max' => $max], $siteUri->uri); return false; } - if ($this->getIsCachedInclude($uri)) { + if ($this->getIsCachedInclude($siteUri->uri)) { return true; } - if ($this->getIsDynamicInclude($uri)) { + if ($this->getIsDynamicInclude($siteUri->uri)) { return false; } @@ -226,12 +224,12 @@ public function getIsCacheableSiteUri(?SiteUriModel $siteUri): bool // Ignore URIs that are resources $resourceBaseUri = trim(parse_url(Craft::getAlias($generalConfig->resourceBaseUrl), PHP_URL_PATH), '/'); - if ($resourceBaseUri && str_starts_with($uri, $resourceBaseUri)) { + if ($resourceBaseUri && str_starts_with($siteUri->uri, $resourceBaseUri)) { return false; } // Ignore URIs that contain `index.php` - if (str_contains($uri, 'index.php')) { + if (str_contains($siteUri->uri, 'index.php')) { Blitz::$plugin->debug('Page not cached because the URL contains `index.php`.', [], $url); return false;