Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent templating being treated as attributes #1035

Merged
merged 4 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
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';
jasonvarga marked this conversation as resolved.
Show resolved Hide resolved

/**
* @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

4 changes: 4 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,10 @@ 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 }}'];
jasonvarga marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down