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
25 changes: 21 additions & 4 deletions src/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/Models/Replacements.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions tests/fixtures/vue-bind/bindings-with-encoded-attributes.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div class="{{class|default('')}}">
<a href="{{isBool ? varA.url : varB.url}}">
<img src="{{isBool ? varA.src : varB.src}}" alt="{{isBool ? varA.alt : varB.alt}}">
</a>
<form method="get" action="{{isBool ? varA.url : varB.url}}">
<label>
<input type="text" name="{{isBool ? varA.name : varB.name}}">
</label>
<input type="submit">
</form>
<a name="{{isBool ? varA.anchor : varB.anchor}}"></a>
</div>
14 changes: 14 additions & 0 deletions tests/fixtures/vue-bind/bindings-with-encoded-attributes.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<template>
<div>
<a :href="isBool ? varA.url : varB.url">
<img :src="isBool ? varA.src : varB.src" :alt="isBool ? varA.alt : varB.alt">
</a>
<form :action="isBool ? varA.url : varB.url" method="get">
<label>
<input type="text" :name="isBool ? varA.name : varB.name">
</label>
<input type="submit">
</form>
<a :name="isBool ? varA.anchor : varB.anchor"/>
</div>
</template>