Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/StaticCaching/DefaultInvalidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ protected function getFormUrls($form)
$prefixedRelativeUrls = Site::all()->map(function ($site) use ($rules) {
return $rules
->reject(fn (string $rule) => URL::isAbsolute($rule))
->map(fn (string $rule) => URL::tidy($site->url().'/'.$rule, withTrailingSlash: false));
->map(fn (string $rule) => URL::tidy($site->url().'/'.$rule));
})->flatten()->all();

return [
Expand All @@ -115,7 +115,7 @@ protected function getAssetUrls($asset)
$prefixedRelativeUrls = Site::all()->map(function ($site) use ($rules) {
return $rules
->reject(fn (string $rule) => URL::isAbsolute($rule))
->map(fn (string $rule) => URL::tidy($site->url().'/'.$rule, withTrailingSlash: false));
->map(fn (string $rule) => URL::tidy($site->url().'/'.$rule));
})->flatten()->all();

return [
Expand All @@ -141,7 +141,7 @@ protected function getEntryUrls($entry)

$prefixedRelativeUrls = $rules
->reject(fn (string $rule) => URL::isAbsolute($rule))
->map(fn (string $rule) => URL::tidy($entry->site()->url().'/'.$rule, withTrailingSlash: false))
->map(fn (string $rule) => URL::tidy($entry->site()->url().'/'.$rule))
->all();

return [
Expand Down Expand Up @@ -170,7 +170,7 @@ protected function getTermUrls($term)

$prefixedRelativeUrls = $rules
->reject(fn (string $rule) => URL::isAbsolute($rule))
->map(fn (string $rule) => URL::tidy($term->site()->url().'/'.$rule, withTrailingSlash: false))
->map(fn (string $rule) => URL::tidy($term->site()->url().'/'.$rule))
->all();

return [
Expand All @@ -192,7 +192,7 @@ protected function getNavUrls($nav)
$prefixedRelativeUrls = $nav->sites()->map(function ($site) use ($rules) {
return $rules
->reject(fn (string $rule) => URL::isAbsolute($rule))
->map(fn (string $rule) => URL::tidy(Site::get($site)->url().'/'.$rule, withTrailingSlash: false));
->map(fn (string $rule) => URL::tidy(Site::get($site)->url().'/'.$rule));
})->flatten()->all();

return [
Expand All @@ -212,7 +212,7 @@ protected function getNavTreeUrls($tree)

$prefixedRelativeUrls = $rules
->reject(fn (string $rule) => URL::isAbsolute($rule))
->map(fn (string $rule) => URL::tidy($tree->site()->url().'/'.$rule, withTrailingSlash: false))
->map(fn (string $rule) => URL::tidy($tree->site()->url().'/'.$rule))
->all();

return [
Expand All @@ -232,7 +232,7 @@ protected function getGlobalUrls($variables)

$prefixedRelativeUrls = $rules
->reject(fn (string $rule) => URL::isAbsolute($rule))
->map(fn (string $rule) => URL::tidy($variables->site()->url().'/'.$rule, withTrailingSlash: false))
->map(fn (string $rule) => URL::tidy($variables->site()->url().'/'.$rule))
->all();

return [
Expand All @@ -252,7 +252,7 @@ protected function getCollectionUrls($collection)
$prefixedRelativeUrls = $collection->sites()->map(function ($site) use ($rules) {
return $rules
->reject(fn (string $rule) => URL::isAbsolute($rule))
->map(fn (string $rule) => URL::tidy(Site::get($site)->url().'/'.$rule, withTrailingSlash: false));
->map(fn (string $rule) => URL::tidy(Site::get($site)->url().'/'.$rule));
})->flatten()->all();

return [
Expand All @@ -270,7 +270,7 @@ protected function getCollectionTreeUrls($tree)

$prefixedRelativeUrls = $rules
->reject(fn (string $rule) => URL::isAbsolute($rule))
->map(fn (string $rule) => URL::tidy($tree->site()->url().'/'.$rule, withTrailingSlash: false))
->map(fn (string $rule) => URL::tidy($tree->site()->url().'/'.$rule))
->all();

return [
Expand Down
47 changes: 47 additions & 0 deletions tests/StaticCaching/DefaultInvalidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Statamic\Contracts\Taxonomies\Taxonomy;
use Statamic\Contracts\Taxonomies\Term;
use Statamic\Facades\Site;
use Statamic\Facades\URL;
use Statamic\Globals\Variables;
use Statamic\StaticCaching\Cacher;
use Statamic\StaticCaching\DefaultInvalidator as Invalidator;
Expand Down Expand Up @@ -388,6 +389,52 @@ public function collection_urls_can_be_invalidated_by_an_entry_in_a_multisite()
$this->assertNull($invalidator->invalidate($entry));
}

#[Test]
public function invalidation_urls_respect_trailing_slash_enforcement()
{
URL::enforceTrailingSlashes();

$cacher = tap(Mockery::mock(Cacher::class), function ($cacher) {
$cacher->shouldReceive('invalidateUrls')->with([
'http://test.com/my/test/entry/',
'http://localhost/blog/three/',
'http://localhost/blog/one/',
'http://localhost/blog/two/',
])->once();
});

$entry = tap(Mockery::mock(Entry::class), function ($m) {
$m->shouldReceive('isRedirect')->andReturn(false);
$m->shouldReceive('absoluteUrl')->andReturn('http://test.com/my/test/entry/');
$m->shouldReceive('collectionHandle')->andReturn('blog');
$m->shouldReceive('descendants')->andReturn(collect());
$m->shouldReceive('site')->andReturn(Site::default());
$m->shouldReceive('parent')->andReturnNull();
$m->shouldReceive('toAugmentedCollection')
->andReturnSelf()
->shouldReceive('merge')
->andReturn(collect([
'parent_uri' => '/my/test/',
]));
});

$invalidator = new Invalidator($cacher, [
'collections' => [
'blog' => [
'urls' => [
'/blog/one/',
'/blog/two/',
'http://localhost/blog/three/',
],
],
],
]);

$this->assertNull($invalidator->invalidate($entry));

URL::enforceTrailingSlashes(false);
}

#[Test]
public function entry_urls_are_not_invalidated_by_an_entry_with_a_redirect()
{
Expand Down
Loading