Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/HtmlParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
14 changes: 10 additions & 4 deletions tests/php/TemplatingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,36 @@ public function testSingleFileComponent(): void {
$this->assertSame( '<div></div>', $result );
}

public function testTemplateHasOnClickHandler_RemoveHandlerFormOutput() {
public function testTemplateHasOnClickHandler_RemoveHandlerFromOutput() {
$result = $this->createAndRender( '<div v-on:click="doStuff"></div>', [] );

$this->assertSame( '<div></div>', $result );
}

public function testTemplateHasOnClickHandlerAndPreventDefault_RemoveHandlerFormOutput() {
public function testTemplateHasOnClickHandlerAndPreventDefault_RemoveHandlerFromOutput() {
$result = $this->createAndRender( '<div v-on:click.prevent="doStuff"></div>', [] );

$this->assertSame( '<div></div>', $result );
}

public function testTemplateHasOnClickHandlerInSomeChildNode_RemoveHandlerFormOutput() {
public function testTemplateHasOnClickHandlerInSomeChildNode_RemoveHandlerFromOutput() {
$result = $this->createAndRender( '<p><a v-on:click="doStuff"></a></p>', [] );

$this->assertSame( '<p><a></a></p>', $result );
}

public function testTemplateHasOnClickHandlerInGrandChildNode_RemoveHandlerFormOutput() {
public function testTemplateHasOnClickHandlerInGrandChildNode_RemoveHandlerFromOutput() {
$result = $this->createAndRender( '<p><b><a v-on:click="doStuff"></a></b></p>', [] );

$this->assertSame( '<p><b><a></a></b></p>', $result );
}

public function testTemplateHasOnClickHandlerWithShorthand_RemoveHandlerFromOutput(): void {
$result = $this->createAndRender( '<p @click="x"></p>', [] );

$this->assertSame( '<p></p>', $result );
}

public function testTemplateHasMultipleEventHandlers_RemoveAll(): void {
$result = $this->createAndRender( '<p v-on:click="x" v-on:keypress="y"></p>', [] );

Expand Down