Skip to content

Commit 6a0de7f

Browse files
committed
Merge branch '2.4'
* 2.4: fixed CS allow the TextAreaFormField to be used with valid/invalid HTML Create security.id.xlf [DependencyInjection] Remove unneeded file [Twig] removed obsolete conditions on Twig versions added lines to exceptions for the trans and transchoice tags [FrameworkBundle] Merged multiple line input into one line to fix the tests. [Form] Make FormInterface::add docblock more explicit [Security] Add zh_CN translations Routing condition bugfix [Validator][Translation]update zh_CN translations [Validator] Minor fix in XmlLoader
2 parents 774674e + 6c11d55 commit 6a0de7f

File tree

22 files changed

+335
-101
lines changed

22 files changed

+335
-101
lines changed

src/Symfony/Bridge/Twig/Node/TransNode.php

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -95,22 +95,10 @@ protected function compileString(\Twig_NodeInterface $body, \Twig_Node_Expressio
9595

9696
preg_match_all('/(?<!%)%([^%]+)%/', $msg, $matches);
9797

98-
if (version_compare(\Twig_Environment::VERSION, '1.5', '>=')) {
99-
foreach ($matches[1] as $var) {
100-
$key = new \Twig_Node_Expression_Constant('%'.$var.'%', $body->getLine());
101-
if (!$vars->hasElement($key)) {
102-
$vars->addElement(new \Twig_Node_Expression_Name($var, $body->getLine()), $key);
103-
}
104-
}
105-
} else {
106-
$current = array();
107-
foreach ($vars as $name => $var) {
108-
$current[$name] = true;
109-
}
110-
foreach ($matches[1] as $var) {
111-
if (!isset($current['%'.$var.'%'])) {
112-
$vars->setNode('%'.$var.'%', new \Twig_Node_Expression_Name($var, $body->getLine()));
113-
}
98+
foreach ($matches[1] as $var) {
99+
$key = new \Twig_Node_Expression_Constant('%'.$var.'%', $body->getLine());
100+
if (!$vars->hasElement($key)) {
101+
$vars->addElement(new \Twig_Node_Expression_Name($var, $body->getLine()), $key);
114102
}
115103
}
116104

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

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

46+
/**
47+
* @expectedException \Twig_Error_Syntax
48+
* @expectedExceptionMessage Unexpected token. Twig was looking for the "with", "from", or "into" keyword in "index" at line 3.
49+
*/
50+
public function testTransUnknownKeyword()
51+
{
52+
$output = $this->getTemplate("{% trans \n\nfoo %}{% endtrans %}")->render();
53+
}
54+
55+
/**
56+
* @expectedException \Twig_Error_Syntax
57+
* @expectedExceptionMessage A message inside a trans tag must be a simple text in "index" at line 2.
58+
*/
59+
public function testTransComplexBody()
60+
{
61+
$output = $this->getTemplate("{% trans %}\n{{ 1 + 2 }}{% endtrans %}")->render();
62+
}
63+
64+
/**
65+
* @expectedException \Twig_Error_Syntax
66+
* @expectedExceptionMessage A message inside a transchoice tag must be a simple text in "index" at line 2.
67+
*/
68+
public function testTransChoiceComplexBody()
69+
{
70+
$output = $this->getTemplate("{% transchoice count %}\n{{ 1 + 2 }}{% endtranschoice %}")->render();
71+
}
72+
4673
public function getTransTests()
4774
{
4875
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);
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
<input
2-
type="<?php echo isset($type) ? $view->escape($type) : 'text' ?>"
3-
<?php echo $view['form']->block($form, 'widget_attributes') ?>
4-
<?php if (!empty($value) || is_numeric($value)): ?> value="<?php echo $view->escape($value) ?>"<?php endif ?>
5-
/>
1+
<input type="<?php echo isset($type) ? $view->escape($type) : 'text' ?>" <?php echo $view['form']->block($form, 'widget_attributes') ?><?php if (!empty($value) || is_numeric($value)): ?> value="<?php echo $view->escape($value) ?>"<?php endif ?> />

src/Symfony/Component/DependencyInjection/services10.xml

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/Symfony/Component/DomCrawler/Field/TextareaFormField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ protected function initialize()
3333

3434
$this->value = null;
3535
foreach ($this->node->childNodes as $node) {
36-
$this->value .= $this->document->saveXML($node);
36+
$this->value .= $node->wholeText;
3737
}
3838
}
3939
}

src/Symfony/Component/DomCrawler/Tests/Field/TextareaFormFieldTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,18 @@ public function testInitialize()
2929
} catch (\LogicException $e) {
3030
$this->assertTrue(true, '->initialize() throws a \LogicException if the node is not a textarea');
3131
}
32+
33+
// Ensure that valid HTML can be used on a textarea.
34+
$node = $this->createNode('textarea', 'foo bar <h1>Baz</h1>');
35+
$field = new TextareaFormField($node);
36+
37+
$this->assertEquals('foo bar <h1>Baz</h1>', $field->getValue(), '->initialize() sets the value of the field to the textarea node value');
38+
39+
// Ensure that we don't do any DOM manipulation/validation by passing in
40+
// "invalid" HTML.
41+
$node = $this->createNode('textarea', 'foo bar <h1>Baz</h2>');
42+
$field = new TextareaFormField($node);
43+
44+
$this->assertEquals('foo bar <h1>Baz</h2>', $field->getValue(), '->initialize() sets the value of the field to the textarea node value');
3245
}
3346
}

src/Symfony/Component/Form/FormInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function setParent(FormInterface $parent = null);
3939
public function getParent();
4040

4141
/**
42-
* Adds a child to the form.
42+
* Adds or replaces a child to the form.
4343
*
4444
* @param FormInterface|string|integer $child The FormInterface instance or the name of the child.
4545
* @param string|null $type The child's type, if a name was passed.

src/Symfony/Component/Routing/Loader/XmlFileLoader.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ protected function parseImport(RouteCollection $collection, \DOMElement $node, $
167167
if (null !== $host) {
168168
$subCollection->setHost($host);
169169
}
170+
if (null !== $condition) {
171+
$subCollection->setCondition($condition);
172+
}
170173
if (null !== $schemes) {
171174
$subCollection->setSchemes($schemes);
172175
}

0 commit comments

Comments
 (0)