Skip to content

Commit 98ce544

Browse files
committed
fix: Pager::only([]) does not work
1 parent 518b912 commit 98ce544

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

system/Pager/Pager.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ class Pager implements PagerInterface
6060
/**
6161
* List of only permitted queries
6262
*
63-
* @var array
63+
* @var list<string>|null
6464
*/
65-
protected $only = [];
65+
protected $only;
6666

6767
/**
6868
* Constructor.
@@ -276,7 +276,7 @@ public function getPageURI(?int $page = null, string $group = 'default', bool $r
276276
$uri->addQuery($this->groups[$group]['pageSelector'], $page);
277277
}
278278

279-
if ($this->only) {
279+
if ($this->only !== null) {
280280
$query = array_intersect_key($_GET, array_flip($this->only));
281281

282282
if (! $segment) {

tests/system/Pager/PagerTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ public function testStoreWithQueries(): void
165165
'http://example.com/?foo=bar&page=5',
166166
$this->pager->only(['foo'])->getPageURI(5)
167167
);
168+
$this->assertSame(
169+
'http://example.com/?page=5',
170+
$this->pager->only([])->getPageURI(5)
171+
);
168172
}
169173

170174
public function testStoreWithSegments(): void
@@ -181,6 +185,10 @@ public function testStoreWithSegments(): void
181185
'http://example.com/5?foo=bar',
182186
$this->pager->only(['foo'])->getPageURI(5)
183187
);
188+
$this->assertSame(
189+
'http://example.com/5',
190+
$this->pager->only([])->getPageURI(5)
191+
);
184192
}
185193

186194
public function testGetPageURIWithURIReturnObject(): void

0 commit comments

Comments
 (0)