From 487f9810297ea0838426a604e9f54594eff4abe2 Mon Sep 17 00:00:00 2001 From: Arif Hoque Date: Fri, 25 Sep 2026 23:25:30 +0600 Subject: [PATCH] Fix Paginator prev/next links leaking merged request input into URLs --- src/Phaseolies/Utilities/Paginator.php | 8 +++++--- tests/PaginatorTest.php | 9 +++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Phaseolies/Utilities/Paginator.php b/src/Phaseolies/Utilities/Paginator.php index a1a4392a..8c0e5d38 100644 --- a/src/Phaseolies/Utilities/Paginator.php +++ b/src/Phaseolies/Utilities/Paginator.php @@ -62,7 +62,8 @@ public function previousPageUrl(): ?string return null; } - $queryParams = request()->except('page'); + $queryParams = request()->query(); + unset($queryParams['page']); return $this->appendQueryParameters($this->data['previous_page_url'], $queryParams); } @@ -78,7 +79,8 @@ public function nextPageUrl(): ?string return null; } - $queryParams = request()->except('page'); + $queryParams = request()->query(); + unset($queryParams['page']); return $this->appendQueryParameters($this->data['next_page_url'], $queryParams); } @@ -106,7 +108,7 @@ public function lastPage(): int /** * Generate an array of page numbers with ellipsis for gaps * - * @return string|null + * @return array */ public function jump(): array { diff --git a/tests/PaginatorTest.php b/tests/PaginatorTest.php index cf553937..4176f920 100644 --- a/tests/PaginatorTest.php +++ b/tests/PaginatorTest.php @@ -98,6 +98,15 @@ public function testNextPageUrl() $this->assertNull($lastPagePaginator->nextPageUrl()); } + public function testPreviousAndNextUrlsIgnoreMergedRequestInput() + { + // Input merged in code is server-side data, not part of the query string + request()->merge(['global_merge_testing_data' => 'doppar']); + + $this->assertEquals('http://example.com?page=4', $this->paginator->previousPageUrl()); + $this->assertEquals('http://example.com?page=6', $this->paginator->nextPageUrl()); + } + public function testCurrentPage() { $this->assertEquals(5, $this->paginator->currentPage());