8000 Merge branch '2.4' · symfony/symfony@6a0de7f · GitHub
[go: up one dir, main page]

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
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ protected function parseImport(RouteCollection $collection, array $config, $path
146146
$requirements = isset($config['requirements']) ? $config['requirements'] : array();
147147
$options = isset($config['options']) ? $config['options'] : array();
148148
$host = isset($config['host']) ? $config['host'] : null;
149+
$condition = isset($config['condition']) ? $config['condition'] : null;
149150
$schemes = isset($config['schemes']) ? $config['schemes'] : null;
150151
$methods = isset($config['methods']) ? $config['methods'] : null;
151152

@@ -157,6 +158,9 @@ protected function parseImport(RouteCollection $collection, array $config, $path
157158
if (null !== $host) {
158159
$subCollection->setHost($host);
159160
}
161+
if (null !== $condition) {
162+
$subCollection->setCondition($condition);
163+
}
160164
if (null !== $schemes) {
161165
$subCollection->setSchemes($schemes);
162166
}

src/Symfony/Component/Routing/Tests/Fixtures/validpattern.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@
2020
<option key="compiler_class">RouteCompiler</option>
2121
<condition>context.getMethod() == "GET"</condition>
2222
</route>
23+
24+
<route id="blog_show_inherited" path="/blog/{slug}" />
2325
</routes>

src/Symfony/Component/Routing/Tests/Fixtures/validpattern.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@ blog_show_legacy:
1717
condition: 'context.getMethod() == "GET"'
1818
options:
1919
compiler_class: RouteCompiler
20+
21+
blog_show_inherited:
22+
path: /blog/{slug}

src/Symfony/Component/Routing/Tests/Fixtures/validresource.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
<default key="foo">123</default>
99
<requirement key="foo">\d+</requirement>
1010
<option key="foo">bar</option>
11+
<condition>context.getMethod() == "POST"</condition>
1112
</import>
1213
</routes>

src/Symfony/Component/Routing/Tests/Fixtures/validresource.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ _blog:
55
requirements: { 'foo': '\d+' }
66
options: { 'foo': 'bar' }
77
host: ""
8+
condition: 'context.getMethod() == "POST"'

src/Symfony/Component/Routing/Tests/Loader/XmlFileLoaderTest.php

Lines changed: 6 additions & 3 deletions
77
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@ public function testLoadWithRoute()
3434
$routeCollection = $loader->load('validpattern.xml');
3535
$routes = $routeCollection->all();
3636

37-
$this->assertCount(2, $routes, 'Two routes are loaded');
37+
$this->assertCount(3, $routes, 'Three routes are loaded');
3838
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
3939

40-
foreach ($routes as $route) {
40+
$identicalRoutes = array_slice($routes, 0, 2);
41+
42+
foreach ($identicalRoutes as $route) {
4143
$this->assertSame('/blog/{slug}', $route->getPath());
4244
$this->assertSame('{locale}.example.com', $route->getHost());
4345
$this->assertSame('MyBundle:Blog:show', $route->getDefault('_controller'));
@@ -72,7 +74,7 @@ public function testLoadWithImport()
7274
$routeCollection = $loader->load('validresource.xml');
7375
$routes = $routeCollection->all();
7476

75-
$this->assertCount(2, $routes, 'Two routes are loaded');
+
$this->assertCount(3, $routes, 'Three routes are loaded');
7678
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
7779

7880
foreach ($routes as $route) {
@@ -81,6 +83,7 @@ public function testLoadWithImport()
8183
$this->assertSame('\d+', $route->getRequirement('foo'));
8284
$this->assertSame('bar', $route->getOption('foo'));
8385
$this->assertSame('', $route->getHost());
86+
$this->assertSame('context.getMethod() == "POST"', $route->getCondition());
8487
}
8588
}
8689

src/Symfony/Component/Routing/Tests/Loader/YamlFileLoaderTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,12 @@ public function testLoadWithRoute()
6868
$routeCollection = $loader->load('validpattern.yml');
6969
$routes = $routeCollection->all();
7070

71-
$this->assertCount(2, $routes, 'Two routes are loaded');
71+
$this->assertCount(3, $routes, 'Three routes are loaded');
7272
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
7373

74-
foreach ($routes as $route) {
74+
$identicalRoutes = array_slice($routes, 0, 2);
75+
76+
foreach ($identicalRoutes as $route) {
7577
$this->assertSame('/blog/{slug}', $route->getPath());
7678
$this->assertSame('{locale}.example.com', $route->getHost());
7779
$this->assertSame('MyBundle:Blog:show', $route->getDefault('_controller'));
@@ -89,7 +91,7 @@ public function testLoadWithResource()
8991
$routeCollection = $loader->load('validresource.yml');
9092
$routes = $routeCollection->all();
9193

92-
$this->assertCount(2, $routes, 'Two routes are loaded');
94+
$this->assertCount(3, $routes, 'Three routes are loaded');
9395
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
9496

9597
foreach ($routes as $route) {
@@ -98,6 +100,8 @@ public function testLoadWithResource()
98100
$this->assertSame('\d+', $route->getRequirement('foo'));
99101
$this->assertSame('bar', $route->getOption('foo'));
100102
$this->assertSame('', $route->getHost());
103+
$this->assertSame('context.getMethod() == "POST"', $route->getCondition());
101104
}
102105
}
106+
103107
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?xml version="1.0"?>
2+
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
3+
<file source-language="en" datatype="plaintext" original="file.ext">
4+
<body>
5+
<trans-unit id="1">
6+
<source>An authentication exception occurred.</source>
7+
<target>Terjadi sebuah pengecualian otentikasi.</target>
8+
</trans-unit>
9+
<trans-unit id="2">
10+
<source>Authentication credentials could not be found.</source>
11+
<target>Kredensial otentikasi tidak bisa ditemukan.</target>
12+
</trans-unit>
13+
<trans-unit id="3">
14+
<source>Authentication request could not be processed due to a system problem.</source>
15+
<target>Permintaan otentikasi tidak bisa diproses karena masalah sistem.</target>
16+
</trans-unit>
17+
<trans-unit id="4">
18+
<source>Invalid credentials.</source>
19+
<target>Kredensial salah.</target>
20+
</trans-unit>
21+
<trans-unit id="5">
22+
<source>Cookie has already been used by someone else.</source>
23+
<target>Cookie sudah digunakan oleh orang lain.</target>
24+
</trans-unit>
25+
<trans-unit id="6">
26+
<source>Not privileged to request the resource.</source>
27+
<target>Tidak berhak untuk meminta sumber daya.</target>
28+
</trans-unit>
29+
<trans-unit id="7">
30+
<source>Invalid CSRF token.</source>
31+
<target>Token CSRF salah.</target>
32+
</trans-unit>
33+
<trans-unit id="8">
34+
<source>Digest nonce has expired.</source>
35+
<target>Digest nonce telah berakhir.</target>
36+
</trans-unit>
37+
<trans-unit id="9">
38+
<source>No authentication provider found to support the authentication token.</source>
39+
<target>Tidak ditemukan penyedia otentikasi untuk mendukung token otentikasi.</target>
40+
</trans-unit>
41+
<trans-unit id="10">
42+
<source>No session available, it either timed out or cookies are not enabled.</source>
43+
<target>Tidak ada sesi yang tersedia, mungkin waktu sudah habis atau cookie tidak diaktifkan</target>
44+
</trans-unit>
45+
<trans-unit id="11">
46+
<source>No token could be found.</source>
47+
<target>Tidak ada token yang bisa ditemukan.</target>
48+
</trans-unit>
49+
<trans-unit id="12">
50+
<source>Username could not be found.</source>
51+
<target>Username tidak bisa ditemukan.</target>
52+
</trans-unit>
53+
<trans-unit id="13">
54+
<source>Account has expired.</source>
55+
<target>Akun telah berakhir.</target>
56+
</trans-unit>
57+
<trans-unit id="14">
58+
<source>Credentials have expired.</source>
59+
<target>Kredensial telah berakhir.</target>
60+
</trans-unit>
61+
<trans-unit id="15">
62+
<source>Account is disabled.</source>
63+
<target>Akun dinonaktifkan.</target>
64+
</trans-unit>
65+
<trans-unit id="16">
66+
<source>Account is locked.</source>
67+
<target>Akun terkunci.</target>
68+
</trans-unit>
69+
</body>
70+
</file>
71+
</xliff>

0 commit comments

Comments
 (0)
0