Skip to content

Commit e47a352

Browse files
committed
Prevent query strings breaking findByUrl ...
Closes #2207 Closes #2230
1 parent aab3680 commit e47a352

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/Sites/Sites.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public function get($handle)
3737

3838
public function findByUrl($url)
3939
{
40+
$url = Str::before($url, '?');
4041
$url = Str::ensureRight($url, '/');
4142

4243
return collect($this->sites)->filter(function ($site) use ($url) {

tests/Sites/SitesTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ public function gets_site_from_url()
122122
// https://github.com/statamic/cms/issues/1874
123123
$this->assertEquals('en', $this->sites->findByUrl('http://test.com/delightful')->handle());
124124
$this->assertEquals('de', $this->sites->findByUrl('http://test.com/de')->handle());
125+
126+
// Make sure that urls that have a query string don't get misinterpreted.
127+
// https://github.com/statamic/cms/issues/2207
128+
$this->assertEquals('en', $this->sites->findByUrl('http://test.com?foo=bar')->handle());
129+
$this->assertEquals('de', $this->sites->findByUrl('http://test.com/de?foo=bar')->handle());
125130
}
126131

127132
/** @test */

0 commit comments

Comments
 (0)