Commit 1dc4ba85 authored by alexpott's avatar alexpott

Issue #2698141 by TravisCarden, ChuChuNaKu, effulgentsia: Empty Twig {% trans...

Issue #2698141 by TravisCarden, ChuChuNaKu, effulgentsia: Empty Twig {% trans %} tag causes unhelpful fatal exception
parent eac023bc
......@@ -169,6 +169,9 @@ protected function compileString(\Twig_Node $body) {
}
}
}
elseif (!$body->hasAttribute('data')) {
throw new \Twig_Error_Syntax('{% trans %} tag cannot be empty');
}
else {
$text = $body->getAttribute('data');
}
......
......@@ -91,6 +91,30 @@ public function testTwigTransTags() {
$this->assertTwigTransTags();
}
/**
* Test empty Twig "trans" tags.
*/
public function testEmptyTwigTransTags() {
$elements = [
'#type' => 'inline_template',
'#template' => '{% trans %}{% endtrans %}',
];
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = \Drupal::service('renderer');
try {
$renderer->renderPlain($elements);
$this->fail('{% trans %}{% endtrans %} did not throw an exception.');
}
catch (\Twig_Error_Syntax $e) {
$this->assertTrue(strstr($e->getMessage(), '{% trans %} tag cannot be empty'), '{% trans %}{% endtrans %} threw the expected exception.');
}
catch (\Exception $e) {
$this->fail('{% trans %}{% endtrans %} threw an unexpected exception.');
}
}
/**
* Asserts Twig trans tags.
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment