Skip to content

Commit

Permalink
TemplateLexer: fixed tag parsing & double syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Oct 31, 2022
1 parent 7a93483 commit 98139c1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/Latte/Compiler/TemplateLexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ final class TemplateLexer
public const NPrefix = 'n:';

/** HTML attribute name/value (\p{C} means \x00-\x1F except space) */
private const ReHtmlName = '[^\p{C} "\'<>=`/{}]+';
private const ReHtmlValue = '[^\p{C} "\'<>=`{}]+';
private const ReAttrName = '[^\p{C} "\'<>=`/]';
private const StateEnd = 'end';

public string $openDelimiter;
Expand Down Expand Up @@ -157,17 +156,17 @@ private function stateHtmlTag(?string $tagName = null, ?string $attrName = null)
(?<Equals>=)|
(?<Quote>["\'])|
(?<Slash>/)?(?<Html_TagClose>>)(?<Newline>[ \t]*\R)?| # > />
(?<Html_Name>' . self::ReHtmlName . ')| # HTML attribute name/value
(?<Html_Name>(?:(?!' . $this->openDelimiter . ')' . self::ReAttrName . ')+)| # HTML attribute name/value
(?<Latte_TagOpen>' . $this->openDelimiter . '(?!\*))| # {tag
(?<Latte_CommentOpen>' . $this->openDelimiter . '\*) # {* comment
~xsiAu');

if (isset($m['Html_Name'])) {
$this->states[0]['args'][1] = $m['Html_Name'];
$this->states[0]['args'][1] = $m['Html_Name']; // sets $attrName
} elseif (isset($m['Equals'])) {
yield from $this->match('~
(?<Whitespace>\s+)? # whitespace
(?<Html_Name>' . self::ReHtmlValue . ') # HTML attribute name/value
(?<Html_Name>(?:(?!' . $this->openDelimiter . ')' . self::ReAttrName . '|/)+) # HTML attribute value can contain /
~xsiAu');
} elseif (isset($m['Whitespace'])) {
} elseif (isset($m['Quote'])) {
Expand Down
8 changes: 8 additions & 0 deletions tests/common/Compiler.samples.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ Assert::match(
);


// latte tag in html tag
Assert::match(
'<a><br {foo}></a>',
$latte->renderToString('<a n:syntax="double"><br {foo}></a>'),
);



// tag name vs content
Assert::contains(
"escapeHtmlText(trim('a'))",
Expand Down

0 comments on commit 98139c1

Please sign in to comment.