Skip to content

Commit

Permalink
Complete the fix
Browse files Browse the repository at this point in the history
  • Loading branch information
bencroker committed Nov 13, 2024
1 parent 4c02b7c commit 6cfc369
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

### Fixed

- Fixed a bug in which URIs could be incorrectly determined to contain uppercase letters during cache generation.
- Fixed a bug that was preventing cache generation when the “Only Cache Lowercase URIs” setting was enabled.

## 5.9.4 - 2024-11-13

Expand Down
24 changes: 16 additions & 8 deletions src/services/CacheRequestService.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,25 +196,27 @@ public function getIsCacheableSiteUri(?SiteUriModel $siteUri): bool
return false;
}

if (Blitz::$plugin->settings->onlyCacheLowercaseUris && preg_match('/\p{Lu}/u', $siteUri->uri)) {
$uri = mb_strtolower($siteUri->uri);

if (Blitz::$plugin->settings->onlyCacheLowercaseUris && $uri !== $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($siteUri->uri) > $max) {
Blitz::$plugin->debug('Page not cached because it exceeds the max URI length of {max}.', ['max' => $max], $siteUri->uri);
if (strlen($uri) > $max) {
Blitz::$plugin->debug('Page not cached because it exceeds the max URI length of {max}.', ['max' => $max], $uri);

return false;
}

if ($this->getIsCachedInclude($siteUri->uri)) {
if ($this->getIsCachedInclude($uri)) {
return true;
}

if ($this->getIsDynamicInclude($siteUri->uri)) {
if ($this->getIsDynamicInclude($uri)) {
return false;
}

Expand All @@ -224,12 +226,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($siteUri->uri, $resourceBaseUri)) {
if ($resourceBaseUri && str_starts_with($uri, $resourceBaseUri)) {
return false;
}

// Ignore URIs that contain `index.php`
if (str_contains($siteUri->uri, 'index.php')) {
if (str_contains($uri, 'index.php')) {
Blitz::$plugin->debug('Page not cached because the URL contains `index.php`.', [], $url);

return false;
Expand Down Expand Up @@ -396,14 +398,20 @@ public function getRequestedCacheableSiteUri(): ?SiteUriModel
$site = Craft::$app->getSites()->getCurrentSite();
$uri = Craft::$app->getRequest()->getFullUri();

$queryParams = Craft::$app->getRequest()->getQueryParams();
$token = Craft::$app->getConfig()->getGeneral()->tokenParam;
if (isset($queryParams[$token])) {
unset($queryParams[$token]);
}

/**
* Build the query string from the query params, so that [[Request::getQueryString()]]
* doesn’t get called, which is determined from the `$_SERVER` global variable
* and which breaks our Pest tests.
*
* @see Request::getQueryString()
*/
$queryString = http_build_query(Craft::$app->getRequest()->getQueryParams());
$queryString = http_build_query($queryParams);

/**
* Remove the base site path from the full URI
Expand Down

0 comments on commit 6cfc369

Please sign in to comment.