Skip to content

Commit

Permalink
Use regexp to determin uppercase letters
Browse files Browse the repository at this point in the history
  • Loading branch information
bencroker committed Nov 13, 2024
1 parent 702658e commit 91e3bf5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
16 changes: 7 additions & 9 deletions src/services/CacheRequestService.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,27 +196,25 @@ 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;
}

// 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;
}

Expand All @@ -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;
Expand Down

0 comments on commit 91e3bf5

Please sign in to comment.