Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions src/StaticCaching/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\ServiceProvider as LaravelServiceProvider;
use Illuminate\Support\Str;
use Statamic\Facades\Cascade;
use Statamic\StaticCaching\NoCache\DatabaseSession;
use Statamic\StaticCaching\NoCache\Session;
Expand Down Expand Up @@ -42,6 +43,10 @@ public function register()
$uri = explode('?', $uri)[0];
}

if (Str::contains($uri, '?')) {
$uri = Str::before($uri, '?').'?'.Request::normalizeQueryString(Str::after($uri, '?'));
}

return match ($driver = config('statamic.static_caching.nocache', 'cache')) {
'cache' => new Session($uri),
'database' => new DatabaseSession($uri),
Expand Down
11 changes: 11 additions & 0 deletions tests/StaticCaching/NoCacheSessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,17 @@ public function it_ignores_the_query_string()
$this->assertEquals('http://localhost/test', $session->url());
}

#[Test]
public function it_normalizes_query_string()
{
$this->get('/test?utm_source=linkedin.com&utm_medium=referral&utm_campaign=foo');

$session = $this->app->make(Session::class);

$this->assertInstanceOf(Session::class, $session);
$this->assertEquals('http://localhost/test?utm_campaign=foo&utm_medium=referral&utm_source=linkedin.com', $session->url());
}

#[Test]
public function it_writes_session_if_a_nocache_tag_is_used()
{
Expand Down