From 3c3c6e7321f0992524b243ce443bf256a3f7e46d Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Fri, 7 Mar 2025 10:59:54 +0000 Subject: [PATCH 1/2] Normalize query string when creating nocache session --- src/StaticCaching/ServiceProvider.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/StaticCaching/ServiceProvider.php b/src/StaticCaching/ServiceProvider.php index 5a025affe4..3cb2726cc1 100644 --- a/src/StaticCaching/ServiceProvider.php +++ b/src/StaticCaching/ServiceProvider.php @@ -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; @@ -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), From c3f0d148dd4f3751b270d30086824dbb296ecfb4 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Fri, 7 Mar 2025 11:11:17 +0000 Subject: [PATCH 2/2] Add test --- tests/StaticCaching/NoCacheSessionTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/StaticCaching/NoCacheSessionTest.php b/tests/StaticCaching/NoCacheSessionTest.php index 4d7ed5caab..00f5c9e2b7 100644 --- a/tests/StaticCaching/NoCacheSessionTest.php +++ b/tests/StaticCaching/NoCacheSessionTest.php @@ -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() {