Skip to content

Commit d17f45f

Browse files
authored
Merge pull request #1035 from jasonvarga/fix-attributes
Prevent templating being treated as attributes
2 parents 0026475 + e60bb31 commit d17f45f

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

src/Extension/Attributes/Util/AttributesHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
final class AttributesHelper
2525
{
2626
private const SINGLE_ATTRIBUTE = '\s*([.]-?[_a-z][^\s}]*|[#][^\s}]+|' . RegexHelper::PARTIAL_ATTRIBUTENAME . RegexHelper::PARTIAL_ATTRIBUTEVALUESPEC . '?)\s*';
27-
private const ATTRIBUTE_LIST = '/^{:?(' . self::SINGLE_ATTRIBUTE . ')+}/i';
27+
private const ATTRIBUTE_LIST = '/^{:?(' . self::SINGLE_ATTRIBUTE . ')+}(?!})/i';
2828

2929
/**
3030
* @return array<string, mixed>

tests/functional/Extension/Attributes/data/special_attributes.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ <h2 class="main shine" id="the-site">The Site</h2>
1313
<p>Attributes without quote and non-whitespace char and a dot <a target="_blank" href="http://url.com" rel="noopener noreferrer">link</a>.</p>
1414
<p>Multiple attributes without quote and non-whitespace char and a dot <a class="class" id="id" target="_blank" href="http://url.com" rel="noopener noreferrer">link</a>.</p>
1515
<p><img valueless-attribute src="/assets/image.jpg" alt="image" /></p>
16+
<p>A paragraph containing {{ mustache }} templating</p>
17+
<p>A paragraph ending with {{ mustache }} templating</p>
18+
<p>{{ mustache }} A paragraph starting with mustache templating</p>

tests/functional/Extension/Attributes/data/special_attributes.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,10 @@ Attributes without quote and non-whitespace char and a dot [link](http://url.com
3030
Multiple attributes without quote and non-whitespace char and a dot [link](http://url.com){#id .class target=_blank}.
3131

3232
![image](/assets/image.jpg){valueless-attribute}
33+
34+
A paragraph containing {{ mustache }} templating
35+
36+
A paragraph ending with {{ mustache }} templating
37+
38+
{{ mustache }} A paragraph starting with mustache templating
39+

tests/unit/Extension/Attributes/Util/AttributesHelperTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ public static function dataForTestParseAttributes(): iterable
101101
// Curly braces inside of values
102102
yield [new Cursor('{: data-json="{1,2,3}" }'), ['data-json' => '{1,2,3}']];
103103
yield [new Cursor('{data-json={1,2,3}} test'), ['data-json' => '{1,2,3}'], ' test'];
104+
105+
// Avoid mustache style templating language being parsed as attributes
106+
yield [new Cursor('{{ foo }}'), [], '{{ foo }}'];
107+
yield [new Cursor(' {{ foo }}'), [], ' {{ foo }}'];
108+
yield [new Cursor('{ foo }}'), [], '{ foo }}'];
104109
}
105110

106111
/**

0 commit comments

Comments
 (0)