Skip to content

Commit eb74cb6

Browse files
committed
bug symfony#10131 added lines to exceptions for the trans and transchoice tags (fabpot)
This PR was merged into the 2.3 branch. Discussion ---------- added lines to exceptions for the trans and transchoice tags | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#10120 | License | MIT | Doc PR | n/a Commits ------- ee0470d added lines to exceptions for the trans and transchoice tags
2 parents aedb919 + ee0470d commit eb74cb6

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

src/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,33 @@ public function testTrans($template, $expected, array $variables = array())
5757
$this->assertEquals($expected, $this->getTemplate($template)->render($variables));
5858
}
5959

60+
/**
61+
* @expectedException \Twig_Error_Syntax
62+
* @expectedExceptionMessage Unexpected token. Twig was looking for the "with", "from", or "into" keyword in "index" at line 3.
63+
*/
64+
public function testTransUnknownKeyword()
65+
{
66+
$output = $this->getTemplate("{% trans \n\nfoo %}{% endtrans %}")->render();
67+
}
68+
69+
/**
70+
* @expectedException \Twig_Error_Syntax
71+
* @expectedExceptionMessage A message inside a trans tag must be a simple text in "index" at line 2.
72+
*/
73+
public function testTransComplexBody()
74+
{
75+
$output = $this->getTemplate("{% trans %}\n{{ 1 + 2 }}{% endtrans %}")->render();
76+
}
77+
78+
/**
79+
* @expectedException \Twig_Error_Syntax
80+
* @expectedExceptionMessage A message inside a transchoice tag must be a simple text in "index" at line 2.
81+
*/
82+
public function testTransChoiceComplexBody()
83+
{
84+
$output = $this->getTemplate("{% transchoice count %}\n{{ 1 + 2 }}{% endtranschoice %}")->render();
85+
}
86+
6087
public function getTransTests()
6188
{
6289
return array(

src/Symfony/Bridge/Twig/TokenParser/TransChoiceTokenParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function parse(\Twig_Token $token)
6464
$body = $this->parser->subparse(array($this, 'decideTransChoiceFork'), true);
6565

6666
if (!$body instanceof \Twig_Node_Text && !$body instanceof \Twig_Node_Expression) {
67-
throw new \Twig_Error_Syntax('A message must be a simple text.');
67+
throw new \Twig_Error_Syntax('A message inside a transchoice tag must be a simple text.', $body->getLine(), $stream->getFilename());
6868
}
6969

7070
$stream->expect(\Twig_Token::BLOCK_END_TYPE);

src/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function parse(\Twig_Token $token)
5555
$stream->next();
5656
$locale = $this->parser->getExpressionParser()->parseExpression();
5757
} elseif (!$stream->test(\Twig_Token::BLOCK_END_TYPE)) {
58-
throw new \Twig_Error_Syntax('Unexpected token. Twig was looking for the "with" or "from" keyword.');
58+
throw new \Twig_Error_Syntax('Unexpected token. Twig was looking for the "with", "from", or "into" keyword.', $stream->getCurrent()->getLine(), $stream->getFilename());
5959
}
6060
}
6161

@@ -64,7 +64,7 @@ public function parse(\Twig_Token $token)
6464
$body = $this->parser->subparse(array($this, 'decideTransFork'), true);
6565

6666
if (!$body instanceof \Twig_Node_Text && !$body instanceof \Twig_Node_Expression) {
67-
throw new \Twig_Error_Syntax('A message inside a trans tag must be a simple text');
67+
throw new \Twig_Error_Syntax('A message inside a trans tag must be a simple text.', $body->getLine(), $stream->getFilename());
6868
}
6969

7070
$stream->expect(\Twig_Token::BLOCK_END_TYPE);

0 commit comments

Comments
 (0)