diff --git a/src/StaticCaching/NoCache/Region.php b/src/StaticCaching/NoCache/Region.php index 52686d9b60..257004d461 100644 --- a/src/StaticCaching/NoCache/Region.php +++ b/src/StaticCaching/NoCache/Region.php @@ -29,7 +29,8 @@ public function context(): array protected function filterContext(array $context) { $context = collect($context) - ->reject(fn ($value, $key) => in_array($key, ['__env', 'app', 'errors', 'resolve', 'resolveComponentsUsing', 'forgetComponentsResolver', 'forgetFactory', 'flushCache', 'constructor'])) + ->reject(fn ($value, $key) => str_starts_with((string) $key, '__')) + ->reject(fn ($value, $key) => in_array($key, ['app', 'errors', 'resolve', 'resolveComponentsUsing', 'forgetComponentsResolver', 'forgetFactory', 'flushCache', 'constructor'])) ->map(function ($value, $key) { if ($value instanceof InvokableComponentVariable) { return $value->resolveDisplayableValue(); diff --git a/tests/StaticCaching/NoCacheSessionTest.php b/tests/StaticCaching/NoCacheSessionTest.php index a0b755c27c..d7651a710e 100644 --- a/tests/StaticCaching/NoCacheSessionTest.php +++ b/tests/StaticCaching/NoCacheSessionTest.php @@ -48,6 +48,22 @@ public function when_pushing_a_region_it_will_filter_out_cascade() ], $region->context()); } + #[Test] + public function when_pushing_a_region_it_will_filter_out_private_variables() + { + $session = new Session('/'); + + $region = $session->pushRegion('', [ + 'foo' => 'bar', + '__env' => 'env value', + '__blaze' => fn () => 'a closure', + ], ''); + + $this->assertEquals([ + 'foo' => 'bar', + ], $region->context()); + } + #[Test] public function it_gets_the_fragment_data() {