Skip to content

Commit

Permalink
TagProcessor: added support for self-closing tags
Browse files Browse the repository at this point in the history
  • Loading branch information
janpecha committed Apr 18, 2024
1 parent 29b398c commit 0f06af5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Processors/TagProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ private function tryParseElement(Utils\StringParser $parser)
$element = new Ast\Element($name);

while ($parser->tryConsumeByMatch('\\s*') !== NULL) {
if ($parser->isCurrent('/>')) { // self-closing
$parser->consumeText('/>');
return $element;
}

$attributeName = $this->parseName($parser);

if ($parser->isCurrent('=')) {
Expand Down
10 changes: 10 additions & 0 deletions tests/Translator/TagProcessor.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,13 @@ test('Empty elements', function () {
'dolor sit amet',
]), $processor->processMessage('Lorem ipsum<br>dolor sit amet'));
});


test('Self-closing elements', function () {
$processor = new TagProcessor;
Assert::equal(new Ast\MessageText([
'Lorem ipsum',
Ast\Element::create('b'),
'dolor sit amet',
]), $processor->processMessage('Lorem ipsum<b />dolor sit amet'));
});

0 comments on commit 0f06af5

Please sign in to comment.