From 967870571b2bcbcee3b035cbcba1cb3acd226f95 Mon Sep 17 00:00:00 2001 From: Lazizbek Ergashev Date: Fri, 28 Aug 2026 12:39:44 +0500 Subject: [PATCH] Fix recache token leaking into pagination links --- .../Pagination/LengthAwarePaginator.php | 6 ++- .../Pagination/LengthAwarePaginatorTest.php | 46 +++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 tests/Extensions/Pagination/LengthAwarePaginatorTest.php diff --git a/src/Extensions/Pagination/LengthAwarePaginator.php b/src/Extensions/Pagination/LengthAwarePaginator.php index 67c00699849..bd4c696f6b7 100644 --- a/src/Extensions/Pagination/LengthAwarePaginator.php +++ b/src/Extensions/Pagination/LengthAwarePaginator.php @@ -4,6 +4,8 @@ use Illuminate\Http\Resources\Json\PaginatedResourceResponse; use Illuminate\Pagination\LengthAwarePaginator as BasePaginator; +use Illuminate\Support\Arr; +use Statamic\Facades\StaticCache; class LengthAwarePaginator extends BasePaginator { @@ -64,7 +66,9 @@ private function pluckResourcesForApi() public function withQueryString() { - $this->appends(request()->query()); + $query = static::resolveQueryString(request()->query()); + + $this->appends(Arr::except($query, StaticCache::recacheTokenParameter())); return $this; } diff --git a/tests/Extensions/Pagination/LengthAwarePaginatorTest.php b/tests/Extensions/Pagination/LengthAwarePaginatorTest.php new file mode 100644 index 00000000000..f3bce896999 --- /dev/null +++ b/tests/Extensions/Pagination/LengthAwarePaginatorTest.php @@ -0,0 +1,46 @@ +get('/?foo=bar'); + + $paginator = $this->paginator()->withQueryString(); + + $this->assertEquals('/?foo=bar&page=2', $paginator->url(2)); + } + + #[Test] + public function it_doesnt_append_the_recache_token() + { + $this->get('/?foo=bar&__recache=abc'); + + $paginator = $this->paginator()->withQueryString(); + + $this->assertEquals('/?foo=bar&page=2', $paginator->url(2)); + } + + #[Test] + public function it_uses_the_query_string_resolver() + { + Paginator::queryStringResolver(fn () => ['foo' => 'bar']); + + $paginator = $this->paginator()->withQueryString(); + + $this->assertEquals('/?foo=bar&page=2', $paginator->url(2)); + } + + private function paginator() + { + return new LengthAwarePaginator(collect(['a', 'b', 'c']), 3, 1, 1, ['path' => '/']); + } +}