diff --git a/src/Compiler.php b/src/Compiler.php index 8b9ca8f..8b688d8 100644 --- a/src/Compiler.php +++ b/src/Compiler.php @@ -38,7 +38,7 @@ protected function parseSelfClosingTags(string $viewContents, Component $compone { $prefix = $this->bladeX->getPrefix(); - $pattern = "/<\s*{$prefix}{$component->tag}\s*(?.*)\s*\/>/"; + $pattern = "/<\s*{$prefix}{$component->tag}\s*(?(?:\s+[\w\-:]+(=(?:\\\"[^\\\"]+\\\"|\'[^\']+\'|[^\'\\\"=<>]+))?)*\s*)\/>/"; return preg_replace_callback($pattern, function (array $matches) use ($component) { $attributes = $this->getAttributesFromAttributeString($matches['attributes']); diff --git a/tests/Features/ComponentCompilation/__snapshots__/ComponentCompilationTest__it_compiles_a_self_closing_component__1.xml b/tests/Features/ComponentCompilation/__snapshots__/ComponentCompilationTest__it_compiles_a_self_closing_component__1.xml index a964d7b..e665fe0 100644 --- a/tests/Features/ComponentCompilation/__snapshots__/ComponentCompilationTest__it_compiles_a_self_closing_component__1.xml +++ b/tests/Features/ComponentCompilation/__snapshots__/ComponentCompilationTest__it_compiles_a_self_closing_component__1.xml @@ -2,5 +2,8 @@
my message +
+
+ my message
diff --git a/tests/Features/ComponentCompilation/__snapshots__/ComponentCompilationTest__it_compiles_a_self_closing_component__2.xml b/tests/Features/ComponentCompilation/__snapshots__/ComponentCompilationTest__it_compiles_a_self_closing_component__2.xml index 11141e6..0922d8b 100644 --- a/tests/Features/ComponentCompilation/__snapshots__/ComponentCompilationTest__it_compiles_a_self_closing_component__2.xml +++ b/tests/Features/ComponentCompilation/__snapshots__/ComponentCompilationTest__it_compiles_a_self_closing_component__2.xml @@ -7,4 +7,10 @@ ['type' => 'error','message' => $message]) ); ?> renderComponent(); ?> + startComponent( + 'components.alert', + array_merge(app(Spatie\BladeX\ContextStack::class)->read(), + ['type' => 'error','message' => $message]) + ); ?> + renderComponent(); ?> diff --git a/tests/Features/ComponentCompilation/stubs/views/selfClosingComponent.blade.php b/tests/Features/ComponentCompilation/stubs/views/selfClosingComponent.blade.php index 8988700..3103ae9 100644 --- a/tests/Features/ComponentCompilation/stubs/views/selfClosingComponent.blade.php +++ b/tests/Features/ComponentCompilation/stubs/views/selfClosingComponent.blade.php @@ -1,3 +1,8 @@ + +