diff --git a/src/Component.php b/src/Component.php index 83934ec..0e1cb5c 100644 --- a/src/Component.php +++ b/src/Component.php @@ -74,7 +74,10 @@ private function stripEventHandlers( DOMNode $node ) { $attributesToRemove = []; /** @var DOMAttr $attribute */ foreach ( $node->attributes as $attribute ) { - if ( str_starts_with( $attribute->name, 'v-on:' ) ) { + if ( + str_starts_with( $attribute->name, 'v-on:' ) || + str_starts_with( $attribute->name, '@' ) + ) { $attributesToRemove[] = $attribute; } } diff --git a/src/HtmlParser.php b/src/HtmlParser.php index b2c42b7..1e15914 100644 --- a/src/HtmlParser.php +++ b/src/HtmlParser.php @@ -48,6 +48,10 @@ public function parseHtml( string $html ): DOMDocument { // discard "Tag xyz invalid" messages from libxml2 < 2.14.0(?) continue; } + if ( $msg === "error parsing attribute name\n" ) { + // discard these messages (e.g. @event="") from libxml < 2.14.0(?) + continue; + } $exception = new Exception( $msg, $error->code, $exception ); } if ( $exception !== null ) { diff --git a/tests/php/TemplatingTest.php b/tests/php/TemplatingTest.php index e8f1108..b002dc5 100644 --- a/tests/php/TemplatingTest.php +++ b/tests/php/TemplatingTest.php @@ -39,30 +39,36 @@ public function testSingleFileComponent(): void { $this->assertSame( '
', $result ); } - public function testTemplateHasOnClickHandler_RemoveHandlerFormOutput() { + public function testTemplateHasOnClickHandler_RemoveHandlerFromOutput() { $result = $this->createAndRender( '', [] ); $this->assertSame( '', $result ); } - public function testTemplateHasOnClickHandlerAndPreventDefault_RemoveHandlerFormOutput() { + public function testTemplateHasOnClickHandlerAndPreventDefault_RemoveHandlerFromOutput() { $result = $this->createAndRender( '', [] ); $this->assertSame( '', $result ); } - public function testTemplateHasOnClickHandlerInSomeChildNode_RemoveHandlerFormOutput() { + public function testTemplateHasOnClickHandlerInSomeChildNode_RemoveHandlerFromOutput() { $result = $this->createAndRender( '', [] ); $this->assertSame( '', $result ); } - public function testTemplateHasOnClickHandlerInGrandChildNode_RemoveHandlerFormOutput() { + public function testTemplateHasOnClickHandlerInGrandChildNode_RemoveHandlerFromOutput() { $result = $this->createAndRender( '', [] ); $this->assertSame( '', $result ); } + public function testTemplateHasOnClickHandlerWithShorthand_RemoveHandlerFromOutput(): void { + $result = $this->createAndRender( '', [] ); + + $this->assertSame( '', $result ); + } + public function testTemplateHasMultipleEventHandlers_RemoveAll(): void { $result = $this->createAndRender( '', [] );