diff --git a/src/Compiler.php b/src/Compiler.php index f71e3e5..3b4fc69 100644 --- a/src/Compiler.php +++ b/src/Compiler.php @@ -406,10 +406,27 @@ private function handleAttributeBinding(DOMElement $node) Replacements::getSanitizedConstant('DOUBLE_CURLY_CLOSE'); } - $node->setAttribute( - $name === 'src' ? Replacements::getSanitizedConstant('SRC_ATTRIBUTE_NAME') : $name, - $this->implodeAttributeValue($name, $dynamicValues, $staticValues) - ); + /** @see https://gitlab.gnome.org/GNOME/libxml2/-/blob/LIBXML2.6.32/HTMLtree.c#L657 */ + switch ($name) { + case 'href': + $name = Replacements::getSanitizedConstant('ATTRIBUTE_NAME_HREF'); + break; + case 'action': + $name = Replacements::getSanitizedConstant('ATTRIBUTE_NAME_ACTION'); + break; + case 'src': + $name = Replacements::getSanitizedConstant('ATTRIBUTE_NAME_SRC'); + break; + case 'name': + if ($node->tagName === 'a') { + $name = Replacements::getSanitizedConstant('ATTRIBUTE_NAME_A_NAME'); + } + break; + default: + break; + } + + $node->setAttribute($name, $this->implodeAttributeValue($name, $dynamicValues, $staticValues)); } } diff --git a/src/Models/Replacements.php b/src/Models/Replacements.php index 01f8a7b..dc4afbe 100644 --- a/src/Models/Replacements.php +++ b/src/Models/Replacements.php @@ -12,7 +12,10 @@ abstract class Replacements extends BasicEnum public const SMALLER = '<'; public const AMPERSAND = '&'; public const PIPE = '|'; - public const SRC_ATTRIBUTE_NAME = 'src'; + public const ATTRIBUTE_NAME_HREF = 'href'; + public const ATTRIBUTE_NAME_ACTION = 'action'; + public const ATTRIBUTE_NAME_SRC = 'src'; + public const ATTRIBUTE_NAME_A_NAME = 'name'; /** * Removes all instances of replacements from target diff --git a/tests/fixtures/vue-bind/bindings-with-encoded-attributes.twig b/tests/fixtures/vue-bind/bindings-with-encoded-attributes.twig new file mode 100644 index 0000000..9c675f7 --- /dev/null +++ b/tests/fixtures/vue-bind/bindings-with-encoded-attributes.twig @@ -0,0 +1,12 @@ +
+ + {{isBool ? varA.alt : varB.alt}} + +
+ + +
+ +
diff --git a/tests/fixtures/vue-bind/bindings-with-encoded-attributes.vue b/tests/fixtures/vue-bind/bindings-with-encoded-attributes.vue new file mode 100644 index 0000000..3d58419 --- /dev/null +++ b/tests/fixtures/vue-bind/bindings-with-encoded-attributes.vue @@ -0,0 +1,14 @@ +