Skip to content

Commit 46aedcd

Browse files
committed
Dont re-escape attributes
1 parent 51651fe commit 46aedcd

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

src/View/StringTemplate.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ public function format(string $name, array $data): string
116116
$finalAttributes = Hash::merge($defaults, $attributes);
117117
}
118118

119+
$finalAttributes['escape'] = false;
120+
119121
$attributesString = $this->formatAttributes($finalAttributes);
120122
$formatted = preg_replace('/<(\w+)([^>]*)>/', '<$1' . $attributesString . '>', $formatted, 1);
121123
}

tests/TestCase/View/StringTemplateTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ public function testNested(): void
167167
public function testNamed(): void
168168
{
169169
$templates = new StringTemplate([
170+
'inputContainer' => '<input type="{{type}}" name="test"{{attrs}}>',
170171
'input_extra_attribs' => [
171172
'template' => '<input type="{{type}}" name="test"{{attrs}}>',
172173
'defaults' => [
@@ -183,5 +184,14 @@ public function testNamed(): void
183184
]);
184185

185186
$this->assertEquals('<input class="otherclass customClass" type="text" name="test">', $formatted);
187+
188+
$formatted2 = $templates->format('inputContainer', [
189+
'attrs' => $this->templater->formatAttributes([
190+
'type' => 'text',
191+
'input-container:class' => 'customClass',
192+
]),
193+
]);
194+
195+
$this->assertEquals('<input class="customClass" type="text" name="test">', $formatted2);
186196
}
187197
}

0 commit comments

Comments
 (0)