File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed
Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change 66use Illuminate \Support \Facades \Blade ;
77use Illuminate \Support \Facades \Event ;
88use Illuminate \Support \ServiceProvider as LaravelServiceProvider ;
9+ use Illuminate \Support \Str ;
910use Statamic \Facades \Cascade ;
1011use Statamic \StaticCaching \NoCache \DatabaseSession ;
1112use Statamic \StaticCaching \NoCache \Session ;
@@ -42,6 +43,10 @@ public function register()
4243 $ uri = explode ('? ' , $ uri )[0 ];
4344 }
4445
46+ if (Str::contains ($ uri , '? ' )) {
47+ $ uri = Str::before ($ uri , '? ' ).'? ' .Request::normalizeQueryString (Str::after ($ uri , '? ' ));
48+ }
49+
4550 return match ($ driver = config ('statamic.static_caching.nocache ' , 'cache ' )) {
4651 'cache ' => new Session ($ uri ),
4752 'database ' => new DatabaseSession ($ uri ),
Original file line number Diff line number Diff line change 66use Illuminate \Support \Facades \Cache ;
77use Mockery ;
88use PHPUnit \Framework \Attributes \Test ;
9+ use Statamic \StaticCaching \Cacher ;
910use Statamic \StaticCaching \NoCache \Session ;
1011use Statamic \StaticCaching \NoCache \StringRegion ;
1112use Tests \FakesContent ;
@@ -171,6 +172,23 @@ public function it_ignores_the_query_string()
171172 $ this ->assertEquals ('http://localhost/test ' , $ session ->url ());
172173 }
173174
175+ #[Test]
176+ public function it_normalizes_query_string ()
177+ {
178+ // Mock the Cacher to return a non-normalized URL.
179+ // In tests, it always returns the current URL, so we have to mock it.
180+ $ cacher = Mockery::mock (Cacher::class);
181+ $ cacher ->shouldReceive ('getUrl ' )
182+ ->andReturn ('http://localhost/test?utm_source=linkedin.com&utm_medium=referral&utm_campaign=foo ' );
183+
184+ $ this ->app ->instance (Cacher::class, $ cacher );
185+
186+ $ session = $ this ->app ->make (Session::class);
187+
188+ $ this ->assertInstanceOf (Session::class, $ session );
189+ $ this ->assertEquals ('http://localhost/test?utm_campaign=foo&utm_medium=referral&utm_source=linkedin.com ' , $ session ->url ());
190+ }
191+
174192 #[Test]
175193 public function it_writes_session_if_a_nocache_tag_is_used ()
176194 {
You can’t perform that action at this time.
0 commit comments