Skip to content

Commit

Permalink
Add check for tags without content
Browse files Browse the repository at this point in the history
  • Loading branch information
richardDobron committed Jun 23, 2022
1 parent 7682866 commit e66794c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/fbt/Transform/FbtTransform/FbtUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace fbt\Transform\FbtTransform;

use fbt\Exceptions\FbtException;
use fbt\Exceptions\FbtParserException;
use function fbt\invariant;
use fbt\Runtime\fbtElement;
Expand Down Expand Up @@ -381,6 +382,11 @@ public static function filterEmptyNodes(array $nodes): array
return $node->innertext;
}

if ($node->isElement() && ! $node->isNamespacedElement() && ! $node->innertext()) {
// todo: this should catch in _createFbtFunctionCallNode
invariant(false, 'text cannot be null');
}

return ! $node->isComment();
}, ARRAY_FILTER_USE_BOTH);

Expand Down
14 changes: 14 additions & 0 deletions tests/fbt/fbtTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace tests\fbt;

use fbt\Exceptions\FbtException;
use fbt\Lib\IntlViewerContext;
use fbt\Runtime\Shared\fbt;
use fbt\Runtime\Shared\FbtHooks;
Expand All @@ -17,6 +18,19 @@ private static function transform($document): string
return FbtTransform::transform($document);
}

public function testDisableTagsWithoutContent()
{
self::expectExceptionMessage('text cannot be null');

self::transform(<<<FBT
<fbt desc="Empty tags test">
first <fbt:param name="text">test</fbt:param>
<p></p>
</fbt>
FBT
);
}

public function testPlural()
{
$fbt = fbt(\fbt\fbt::plural('translator', 2, ['showCount' => 'yes', 'count' => 2]), 'Plural word test');
Expand Down

0 comments on commit e66794c

Please sign in to comment.