Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dd744c9

Browse files
committed
Merge branch '2.3' into 2.6
* 2.3: Fix typo Check instance of FormBuilderInterface instead of FormBuilder [Security] TokenBasedRememberMeServices test to show why encoding username is required [Security] AbstractRememberMeServices::encodeCookie() validates cookie parts [console][formater] allow format toString object. [HttpFoundation] Fix baseUrl when script filename is contained in pathInfo Avoid redirection to XHR URIs [HttpFoundation] IpUtils::checkIp4() should allow networks Fix HTML escaping of to-source links [FrameworkBundle] Removed unnecessary parameter in TemplateController [DomCrawler] Throw an exception if a form field path is incomplete. [Console] Delete duplicate test in CommandTest [TwigBundle] Refresh twig paths when resources change. WebProfiler break words fixed typo Update README.md [HttpKernel] Handle an array vary header in the http cache store [Security][Translation] fixes #14584 [Framework] added test for Router commands. Handled bearer authorization header in REDIRECT_ form Conflicts: src/Symfony/Component/Debug/ExceptionHandler.php
2 parents 836a661 + cc749a6 commit dd744c9

File tree

31 files changed

+385
-45
lines changed

31 files changed

+385
-45
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ work for you:
3333
Installation
3434
------------
3535

36-
The best way to install Symfony is to download the Symfony Standard Edition
37-
available at <https://symfony.com/download>.
36+
The best way to install Symfony is to use the [official Symfony Installer][7].
37+
It allows you to start a new project based on the version you want.
3838

3939
Documentation
4040
-------------
@@ -64,3 +64,4 @@ Information on how to run the Symfony test suite can be found in the
6464
[4]: https://symfony.com/doc/current/contributing/code/patches.html#check-list
6565
[5]: https://symfony.com/doc/current/contributing/code/patches.html#make-a-pull-request
6666
[6]: https://symfony.com/doc/master/contributing/code/tests.html
67+
[7]: https://symfony.com/doc/current/book/installation.html#installing-the-symfony-installer

src/Symfony/Bridge/Twig/Extension/CodeExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function getFilters()
4949
new \Twig_SimpleFilter('file_excerpt', array($this, 'fileExcerpt'), array('is_safe' => array('html'))),
5050
new \Twig_SimpleFilter('format_file', array($this, 'formatFile'), array('is_safe' => array('html'))),
5151
new \Twig_SimpleFilter('format_file_from_text', array($this, 'formatFileFromText'), array('is_safe' => array('html'))),
52-
new \Twig_SimpleFilter('file_link', array($this, 'getFileLink'), array('is_safe' => array('html'))),
52+
new \Twig_SimpleFilter('file_link', array($this, 'getFileLink')),
5353
);
5454
}
5555

src/Symfony/Bundle/FrameworkBundle/Controller/TemplateController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function templateAction($template, $maxAge = null, $sharedAge = null, $pr
4747
if ($private) {
4848
$response->setPrivate();
4949
} elseif ($private === false || (null === $private && ($maxAge || $sharedAge))) {
50-
$response->setPublic($private);
50+
$response->setPublic();
5151
}
5252

5353
return $response;

src/Symfony/Bundle/FrameworkBundle/Resources/public/css/body.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ build: 56
5252
background-color: #FFFFFF;
5353
border: 1px solid #dfdfdf;
5454
padding: 40px 50px;
55+
word-break: break-all;
5556
}
5657
.sf-reset h2 {
5758
font-size: 16px;

src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,24 +154,25 @@ public function fileExcerpt($file, $line)
154154
*/
155155
public function formatFile($file, $line, $text = null)
156156
{
157+
if (PHP_VERSION_ID >= 50400) {
158+
$flags = ENT_QUOTES | ENT_SUBSTITUTE;
159+
} else {
160+
$flags = ENT_QUOTES;
161+
}
162+
157163
if (null === $text) {
158164
$file = trim($file);
159165
$fileStr = $file;
160166
if (0 === strpos($fileStr, $this->rootDir)) {
161167
$fileStr = str_replace($this->rootDir, '', str_replace('\\', '/', $fileStr));
162-
$fileStr = sprintf('<abbr title="%s">kernel.root_dir</abbr>/%s', $this->rootDir, $fileStr);
168+
$fileStr = htmlspecialchars($fileStr, $flags, $this->charset);
169+
$fileStr = sprintf('<abbr title="%s">kernel.root_dir</abbr>/%s', htmlspecialchars($this->rootDir, $flags, $this->charset), $fileStr);
163170
}
164171

165-
$text = "$fileStr at line $line";
172+
$text = sprintf('%s at line %d', $fileStr, $line);
166173
}
167174

168175
if (false !== $link = $this->getFileLink($file, $line)) {
169-
if (PHP_VERSION_ID >= 50400) {
170-
$flags = ENT_QUOTES | ENT_SUBSTITUTE;
171-
} else {
172-
$flags = ENT_QUOTES;
173-
}
174-
175176
return sprintf('<a href="%s" title="Click to open this file" class="file_link">%s</a>', htmlspecialchars($link, $flags, $this->charset), $text);
176177
}
177178

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Tests\Command;
13+
14+
use Symfony\Component\Console\Application;
15+
use Symfony\Component\Console\Tester\CommandTester;
16+
use Symfony\Bundle\FrameworkBundle\Command\RouterDebugCommand;
17+
use Symfony\Component\Routing\Route;
18+
use Symfony\Component\Routing\RouteCollection;
19+
20+
class RouterDebugCommandTest extends \PHPUnit_Framework_TestCase
21+
{
22+
public function testDebugAllRoutes()
23+
{
24+
$tester = $this->createCommandTester();
25+
$ret = $tester->execute(array('name' => null));
26+
27+
$this->assertEquals(0, $ret, 'Returns 0 in case of success');
28+
$this->assertContains('[router] Current routes', $tester->getDisplay());
29+
}
30+
31+
public function testDebugSingleRoute()
32+
{
33+
$tester = $this->createCommandTester();
34+
$ret = $tester->execute(array('name' => 'foo'));
35+
36+
$this->assertEquals(0, $ret, 'Returns 0 in case of success');
37+
$this->assertContains('[router] Route "foo"', $tester->getDisplay());
38+
}
39+
40+
/**
41+
* @expectedException \InvalidArgumentException
42+
*/
43+
public function testDebugInvalidRoute()
44+
{
45+
$this->createCommandTester()->execute(array('name' => 'test'));
46+
}
47+
48+
/**
49+
* @return CommandTester
50+
*/
51+
private function createCommandTester()
52+
{
53+
$application = new Application();
54+
55+
$command = new RouterDebugCommand();
56+
$command->setContainer($this->getContainer());
57+
$application->add($command);
58+
59+
return new CommandTester($application->find('router:debug'));
60+
}
61+
62+
private function getContainer()
63+
{
64+
$routeCollection = new RouteCollection();
65+
$routeCollection->add('foo', new Route('foo'));
66+
$router = $this->getMock('Symfony\Component\Routing\RouterInterface');
67+
$router
68+
->expects($this->atLeastOnce())
69+
->method('getRouteCollection')
70+
->will($this->returnValue($routeCollection))
71+
;
72+
73+
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
74+
$container
75+
->expects($this->once())
76+
->method('has')
77+
->with('router')
78+
->will($this->returnValue(true))
79+
;
80+
$container
81+
->expects($this->atLeastOnce())
82+
->method('get')
83+
->with('router')
84+
->will($this->returnValue($router))
85+
;
86+
87+
return $container;
88+
}
89+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Tests\Command;
13+
14+
use Symfony\Component\Console\Application;
15+
use Symfony\Component\Console\Tester\CommandTester;
16+
use Symfony\Bundle\FrameworkBundle\Command\RouterMatchCommand;
17+
use Symfony\Bundle\FrameworkBundle\Command\RouterDebugCommand;
18+
use Symfony\Component\Routing\Route;
19+
use Symfony\Component\Routing\RouteCollection;
20+
use Symfony\Component\Routing\RequestContext;
21+
22+
class RouterMatchCommandTest extends \PHPUnit_Framework_TestCase
23+
{
24+
public function testWithMatchPath()
25+
{
26+
$tester = $this->createCommandTester();
27+
$ret = $tester->execute(array('path_info' => '/foo', 'foo'));
28+
29+
$this->assertEquals(0, $ret, 'Returns 0 in case of success');
30+
$this->assertContains('[router] Route "foo"', $tester->getDisplay());
31+
}
32+
33+
public function testWithNotMatchPath()
34+
{
35+
$tester = $this->createCommandTester();
36+
$ret = $tester->execute(array('path_info' => '/test', 'foo'));
37+
38+
$this->assertEquals(1, $ret, 'Returns 1 in case of failure');
39+
$this->assertContains('None of the routes match the path "/test"', $tester->getDisplay());
40+
}
41+
42+
/**
43+
* @return CommandTester
44+
*/
45+
private function createCommandTester()
46+
{
47+
$application = new Application();
48+
49+
$command = new RouterMatchCommand();
50+
$command->setContainer($this->getContainer());
51+
$application->add($command);
52+
53+
$command = new RouterDebugCommand();
54+
$command->setContainer($this->getContainer());
55+
$application->add($command);
56+
57+
return new CommandTester($application->find('router:match'));
58+
}
59+
60+
private function getContainer()
61+
{
62+
$routeCollection = new RouteCollection();
63+
$routeCollection->add('foo', new Route('foo'));
64+
$requestContext = new RequestContext();
65+
$router = $this->getMock('Symfony\Component\Routing\RouterInterface');
66+
$router
67+
->expects($this->any())
68+
->method('getRouteCollection')
69+
->will($this->returnValue($routeCollection))
70+
;
71+
$router
72+
->expects($this->any())
73+
->method('getContext')
74+
->will($this->returnValue($requestContext))
75+
;
76+
77+
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
78+
$container
79+
->expects($this->once())
80+
->method('has')
81+
->with('router')
82+
->will($this->returnValue(true))
83+
;
84+
$container
85+
->expects($this->atLeastOnce())
86+
->method('get')
87+
->with('router')
88+
->will($this->returnValue($router))
89+
;
90+
91+
return $container;
92+
}
93+
}

src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\TwigBundle\DependencyInjection;
1313

1414
use Symfony\Component\Config\FileLocator;
15+
use Symfony\Component\Config\Resource\DirectoryResource;
1516
use Symfony\Component\DependencyInjection\ContainerBuilder;
1617
use Symfony\Component\DependencyInjection\Reference;
1718
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
@@ -66,22 +67,26 @@ public function load(array $configs, ContainerBuilder $container)
6667
} else {
6768
$twigFilesystemLoaderDefinition->addMethodCall('addPath', array($path, $namespace));
6869
}
70+
$container->addResource(new DirectoryResource($path));
6971
}
7072

7173
// register bundles as Twig namespaces
7274
foreach ($container->getParameter('kernel.bundles') as $bundle => $class) {
7375
if (is_dir($dir = $container->getParameter('kernel.root_dir').'/Resources/'.$bundle.'/views')) {
7476
$this->addTwigPath($twigFilesystemLoaderDefinition, $dir, $bundle);
77+
$container->addResource(new DirectoryResource($dir));
7578
}
7679

7780
$reflection = new \ReflectionClass($class);
7881
if (is_dir($dir = dirname($reflection->getFilename()).'/Resources/views')) {
7982
$this->addTwigPath($twigFilesystemLoaderDefinition, $dir, $bundle);
83+
$container->addResource(new DirectoryResource($dir));
8084
}
8185
}
8286

8387
if (is_dir($dir = $container->getParameter('kernel.root_dir').'/Resources/views')) {
8488
$twigFilesystemLoaderDefinition->addMethodCall('addPath', array($dir));
89+
$container->addResource(new DirectoryResource($dir));
8590
}
8691

8792
if (!empty($config['globals'])) {

src/Symfony/Component/Console/Formatter/OutputFormatter.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ public function getStyle($name)
142142
*/
143143
public function format($message)
144144
{
145+
$message = (string) $message;
145146
$offset = 0;
146147
$output = '';
147148
$tagRegex = '[a-z][a-z0-9_=;-]*';

src/Symfony/Component/Console/Tests/Command/CommandTest.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,6 @@ public function testGetHelper()
167167
$this->assertEquals($formatterHelper->getName(), $command->getHelper('formatter')->getName(), '->getHelper() returns the correct helper');
168168
}
169169

170-
public function testGet()
171-
{
172-
$application = new Application();
173-
$command = new \TestCommand();
174-
$command->setApplication($application);
175-
$formatterHelper = new FormatterHelper();
176-
$this->assertEquals($formatterHelper->getName(), $command->getHelper('formatter')->getName(), '->__get() returns the correct helper');
177-
}
178-
179170
public function testMergeApplicationDefinition()
180171
{
181172
$application1 = new Application();

src/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,14 @@ public function testFormatLongString()
166166
$this->assertEquals("\033[37;41msome error\033[39;49m".$long, $formatter->format('<error>some error</error>'.$long));
167167
}
168168

169+
public function testFormatToStringObject()
170+
{
171+
$formatter = new OutputFormatter(false);
172+
$this->assertEquals(
173+
'some info', $formatter->format(new TableCell())
174+
);
175+
}
176+
169177
public function testNotDecoratedFormatter()
170178
{
171179
$formatter = new OutputFormatter(false);
@@ -255,3 +263,11 @@ public function testContentWithLineBreaks()
255263
));
256264
}
257265
}
266+
267+
class TableCell
268+
{
269+
public function __toString()
270+
{
271+
return '<info>some info</info>';
272+
}
273+
}

src/Symfony/Component/DomCrawler/FormFieldRegistry.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,15 @@ public function has($name)
124124
public function set($name, $value)
125125
{
126126
$target = &$this->get($name);
127-
if (!is_array($value) || $target instanceof Field\ChoiceFormField) {
127+
if ((!is_array($value) && $target instanceof Field\FormField) || $target instanceof Field\ChoiceFormField) {
128128
$target->setValue($value);
129-
} else {
129+
} elseif (is_array($value)) {
130130
$fields = self::create($name, $value);
131131
foreach ($fields->all() as $k => $v) {
132132
$this->set($k, $v);
133133
}
134+
} else {
135+
throw new \InvalidArgumentException(sprintf('Cannot set value on a compound field "%s".', $name));
134136
}
135137
}
136138

src/Symfony/Component/DomCrawler/Tests/FormTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,31 @@ public function testFormRegistrySetValues()
807807
));
808808
}
809809

810+
/**
811+
* @expectedException \InvalidArgumentException
812+
* @expectedExceptionMessage Cannot set value on a compound field "foo[bar]".
813+
*/
814+
public function testFormRegistrySetValueOnCompoundField()
815+
{
816+
$registry = new FormFieldRegistry();
817+
$registry->add($this->getFormFieldMock('foo[bar][baz]'));
818+
819+
$registry->set('foo[bar]', 'fbb');
820+
}
821+
822+
/**
823+
* @expectedException InvalidArgumentException
824+
* @expectedExceptionMessage Unreachable field "0"
825+
*/
826+
public function testFormRegistrySetArrayOnNotCompoundField()
827+
{
828+
829+
$registry = new FormFieldRegistry();
830+
$registry->add($this->getFormFieldMock('bar'));
831+
832+
$registry->set('bar', array('baz'));
833+
}
834+
810835
public function testDifferentFieldTypesWithSameName()
811836
{
812837
$dom = new \DOMDocument();

0 commit comments

Comments
 (0)