diff --git a/src/Xray.php b/src/Xray.php index 8dcfc78..678c661 100644 --- a/src/Xray.php +++ b/src/Xray.php @@ -34,7 +34,7 @@ public function modifyView($view) $file = tempnam(sys_get_temp_dir(), $view->name()); - $re = '/(@section\(([^))]+)\))(.*?)(@endsection|@show|@overwrite)/s'; + $re = '/(@section\(([^))]+)\)+)(.*?)(@endsection|@show|@overwrite)/s'; $viewContent = preg_replace_callback($re, function ($matches) use ($view) { ++$this->viewId; $sectionName = str_replace(["'", '"'], '', $matches[2]); @@ -60,4 +60,4 @@ protected function isEnabledForView(string $viewName): bool return ! in_array($viewName, config('xray.excluded', [])); } -} \ No newline at end of file +} diff --git a/tests/XrayTest.php b/tests/XrayTest.php index 3c91e37..c6a66b4 100644 --- a/tests/XrayTest.php +++ b/tests/XrayTest.php @@ -34,4 +34,16 @@ public function it_does_not_apply_middleware_on_json_responses() $this->get('/')->assertJson($data); } + + /** @test */ + public function it_adds_xray_when_using_parenthesis_on_sections() + { + Route::get('/', function() { + return view('example2'); + }); + + $response = $this->get('/'); + + $this->assertMatchesSnapshot($response->getContent()); + } } diff --git a/tests/__snapshots__/XrayTest__it_adds_xray_when_using_parenthesis_on_sections__1.php b/tests/__snapshots__/XrayTest__it_adds_xray_when_using_parenthesis_on_sections__1.php new file mode 100644 index 0000000..903e66f --- /dev/null +++ b/tests/__snapshots__/XrayTest__it_adds_xray_when_using_parenthesis_on_sections__1.php @@ -0,0 +1,636 @@ + + + + + + + + + + main.title + + + + + + +'; diff --git a/tests/views/example2.blade.php b/tests/views/example2.blade.php new file mode 100644 index 0000000..61f8b94 --- /dev/null +++ b/tests/views/example2.blade.php @@ -0,0 +1,6 @@ +@extends('layout2') + +@section('title', trans('main.title')) + +@section('content') +@endsection \ No newline at end of file diff --git a/tests/views/layout2.blade.php b/tests/views/layout2.blade.php new file mode 100644 index 0000000..4a5f16e --- /dev/null +++ b/tests/views/layout2.blade.php @@ -0,0 +1,8 @@ + + + @yield('title') + + +@yield('content') + + \ No newline at end of file