Skip to content

Commit

Permalink
Merge pull request #1035 from jasonvarga/fix-attributes
Browse files Browse the repository at this point in the history
Prevent templating being treated as attributes
  • Loading branch information
colinodell authored Jul 24, 2024
2 parents 0026475 + e60bb31 commit d17f45f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Extension/Attributes/Util/AttributesHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
final class AttributesHelper
{
private const SINGLE_ATTRIBUTE = '\s*([.]-?[_a-z][^\s}]*|[#][^\s}]+|' . RegexHelper::PARTIAL_ATTRIBUTENAME . RegexHelper::PARTIAL_ATTRIBUTEVALUESPEC . '?)\s*';
private const ATTRIBUTE_LIST = '/^{:?(' . self::SINGLE_ATTRIBUTE . ')+}/i';
private const ATTRIBUTE_LIST = '/^{:?(' . self::SINGLE_ATTRIBUTE . ')+}(?!})/i';

/**
* @return array<string, mixed>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ <h2 class="main shine" id="the-site">The Site</h2>
<p>Attributes without quote and non-whitespace char and a dot <a target="_blank" href="http://url.com" rel="noopener noreferrer">link</a>.</p>
<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>
<p><img valueless-attribute src="/assets/image.jpg" alt="image" /></p>
<p>A paragraph containing {{ mustache }} templating</p>
<p>A paragraph ending with {{ mustache }} templating</p>
<p>{{ mustache }} A paragraph starting with mustache templating</p>
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,10 @@ Attributes without quote and non-whitespace char and a dot [link](http://url.com
Multiple attributes without quote and non-whitespace char and a dot [link](http://url.com){#id .class target=_blank}.

![image](/assets/image.jpg){valueless-attribute}

A paragraph containing {{ mustache }} templating

A paragraph ending with {{ mustache }} templating

{{ mustache }} A paragraph starting with mustache templating

5 changes: 5 additions & 0 deletions tests/unit/Extension/Attributes/Util/AttributesHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ public static function dataForTestParseAttributes(): iterable
// Curly braces inside of values
yield [new Cursor('{: data-json="{1,2,3}" }'), ['data-json' => '{1,2,3}']];
yield [new Cursor('{data-json={1,2,3}} test'), ['data-json' => '{1,2,3}'], ' test'];

// Avoid mustache style templating language being parsed as attributes
yield [new Cursor('{{ foo }}'), [], '{{ foo }}'];
yield [new Cursor(' {{ foo }}'), [], ' {{ foo }}'];
yield [new Cursor('{ foo }}'), [], '{ foo }}'];
}

/**
Expand Down

0 comments on commit d17f45f

Please sign in to comment.