Skip to content

Commit a67f5d0

Browse files
committed
Merge branch '2.3'
* 2.3: [Process] Revert change [Process] Fix #8746 : slowness added in unit tests since #8741 [Process] Fix #8742 : Signal-terminated processes are not successful corrected English grammar (s/does not exists/does not exist) [Process] Add more precision to Process::stop timeout [Process] Avoid zombie process in case of unit tests failure [Process] Fix #8739 [Process] Add failing test for #8739 [Process] Fix CS [TwigBridge] removed superflous ; when rendering form_enctype() (closes #8660) Fixed documentation grammar for AuthenticationManagerInterface::authenticate() [Validator] fixed the wrong isAbstract() check against the class (fixed #8589) [TwigBridge] Prevent code extension to display warning Fix internal sub-request creation [FrameworkBundle] made code more generic [Form] Moved auto_initialize option to the BaseType Use strstr instead of strpos Make sure ContextErrorException is loaded during compile time errors Fix empty process argument escaping on Windows Ignore null value in comparison validators Conflicts: src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php src/Symfony/Component/HttpKernel/Tests/Fragment/InlineFragmentRendererTest.php src/Symfony/Component/Process/Process.php
2 parents 6526da8 + 4af7276 commit a67f5d0

38 files changed

+427
-220
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ public function formatArgsAsText($args)
137137
public function fileExcerpt($file, $line)
138138
{
139139
if (is_readable($file)) {
140-
$code = highlight_file($file, true);
140+
// highlight_file could throw warnings
141+
// see https://bugs.php.net/bug.php?id=25725
142+
$code = @highlight_file($file, true);
141143
// remove main code/span tags
142144
$code = preg_replace('#^<code.*?>\s*<span.*?>(.*)</span>\s*</code>#s', '\\1', $code);
143145
$content = preg_split('#<br />#', $code);

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ public function compile(\Twig_Compiler $compiler)
2323
{
2424
parent::compile($compiler);
2525

26-
$compiler->raw(";\n");
27-
2826
// Uncomment this as soon as the deprecation note should be shown
2927
// $compiler->write('trigger_error(\'The helper form_enctype(form) is deprecated since version 2.3 and will be removed in 3.0. Use form_start(form) instead.\', E_USER_DEPRECATED)');
3028
}

src/Symfony/Bundle/FrameworkBundle/Console/Application.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Console;
1313

14-
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
14+
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
1515
use Symfony\Component\Console\Application as BaseApplication;
1616
use Symfony\Component\Console\Input\InputInterface;
1717
use Symfony\Component\Console\Input\InputOption;
@@ -78,7 +78,7 @@ public function doRun(InputInterface $input, OutputInterface $output)
7878
$container = $this->kernel->getContainer();
7979

8080
foreach ($this->all() as $command) {
81-
if ($command instanceof ContainerAwareCommand) {
81+
if ($command instanceof ContainerAwareInterface) {
8282
$command->setContainer($container);
8383
}
8484
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ public function fileExcerpt($file, $line)
131131
}
132132
}
133133

134-
$code = highlight_file($file, true);
134+
// highlight_file could throw warnings
135+
// see https://bugs.php.net/bug.php?id=25725
136+
$code = @highlight_file($file, true);
135137
// remove main code/span tags
136138
$code = preg_replace('#^<code.*?>\s*<span.*?>(.*)</span>\s*</code>#s', '\\1', $code);
137139
$content = preg_split('#<br />#', $code);

src/Symfony/Component/ClassLoader/ClassLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public function findFile($class)
177177
$classPath .= str_replace('_', DIRECTORY_SEPARATOR, $className).'.php';
178178

179179
foreach ($this->prefixes as $prefix => $dirs) {
180-
if (0 === strpos($class, $prefix)) {
180+
if ($class === strstr($class, $prefix)) {
181181
foreach ($dirs as $dir) {
182182
if (file_exists($dir.DIRECTORY_SEPARATOR.$classPath)) {
183183
return $dir.DIRECTORY_SEPARATOR.$classPath;

src/Symfony/Component/Debug/ErrorHandler.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ function ($row) {
139139
}
140140

141141
if ($this->displayErrors && error_reporting() & $level && $this->level & $level) {
142+
// make sure the ContextErrorException class is loaded (https://bugs.php.net/bug.php?id=65322)
143+
if (!class_exists('Symfony\Component\Debug\Exception\ContextErrorException')) {
144+
require __DIR__.'/Exception/ContextErrorException.php';
145+
}
146+
142147
throw new ContextErrorException(sprintf('%s: %s in %s line %d', isset($this->levels[$level]) ? $this->levels[$level] : $level, $message, $file, $line), 0, $level, $file, $line, $context);
143148
}
144149

src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,32 @@
2020
*/
2121
class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
2222
{
23+
public function testCompileTimeError()
24+
{
25+
// the ContextErrorException must not be loaded for this test to work
26+
if (class_exists('Symfony\Component\Debug\Exception\ContextErrorException', false)) {
27+
$this->markTestSkipped('The ContextErrorException class is already loaded.');
28+
}
29+
30+
$handler = ErrorHandler::register(E_ALL | E_STRICT);
31+
$displayErrors = ini_get('display_errors');
32+
ini_set('display_errors', '1');
33+
34+
try {
35+
// trigger compile time error
36+
eval(<<<'PHP'
37+
class _BaseCompileTimeError { function foo() {} }
38+
class _CompileTimeError extends _BaseCompileTimeError { function foo($invalid) {} }
39+
PHP
40+
);
41+
} catch(\Exception $e) {
42+
// if an exception is thrown, the test passed
43+
}
44+
45+
ini_set('display_errors', $displayErrors);
46+
restore_error_handler();
47+
}
48+
2349
public function testConstruct()
2450
{
2551
$handler = ErrorHandler::register(3);

src/Symfony/Component/Finder/Shell/Command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public function ins($label)
187187
public function get($label)
188188
{
189189
if (!isset($this->labels[$label])) {
190-
throw new \RuntimeException(sprintf('Label "%s" does not exists.', $label));
190+
throw new \RuntimeException(sprintf('Label "%s" does not exist.', $label));
191191
}
192192

193193
return $this->bits[$this->labels[$label]];

src/Symfony/Component/Form/Extension/Core/Type/BaseType.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ abstract class BaseType extends AbstractType
3333
public function buildForm(FormBuilderInterface $builder, array $options)
3434
{
3535
$builder->setDisabled($options['disabled']);
36+
$builder->setAutoInitialize($options['auto_initialize']);
3637
}
3738

3839
/**
@@ -112,6 +113,7 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
112113
'label' => null,
113114
'attr' => array(),
114115
'translation_domain' => null,
116+
'auto_initialize' => true,
115117
));
116118

117119
$resolver->setAllowedTypes(array(

src/Symfony/Component/Form/Extension/Core/Type/ButtonType.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Form\Extension\Core\Type;
1313

1414
use Symfony\Component\Form\ButtonTypeInterface;
15+
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
1516

1617
/**
1718
* A form button.
@@ -35,4 +36,16 @@ public function getName()
3536
{
3637
return 'button';
3738
}
39+
40+
/**
41+
* {@inheritdoc}
42+
*/
43+
public function setDefaultOptions(OptionsResolverInterface $resolver)
44+
{
45+
parent::setDefaultOptions($resolver);
46+
47+
$resolver->setDefaults(array(
48+
'auto_initialize' => false,
49+
));
50+
}
3851
}

src/Symfony/Component/Form/Extension/Core/Type/FormType.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ public function buildForm(FormBuilderInterface $builder, array $options)
5555
->setDataMapper($options['compound'] ? new PropertyPathMapper($this->propertyAccessor) : null)
5656
->setMethod($options['method'])
5757
->setAction($options['action'])
58-
->setAutoInitialize($options['auto_initialize'])
5958
;
6059

6160
if ($options['trim']) {
@@ -188,7 +187,6 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
188187
// According to RFC 2396 (http://www.ietf.org/rfc/rfc2396.txt)
189188
// section 4.2., empty URIs are considered same-document references
190189
'action' => '',
191-
'auto_initialize' => true,
192190
));
193191

194192
$resolver->setAllowedTypes(array(

src/Symfony/Component/Form/Tests/Extension/Core/Type/SubmitTypeTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,13 @@ public function testClickedIfSubmittedWithUnemptyString()
5151

5252
$this->assertTrue($button->isClicked());
5353
}
54+
55+
public function testSubmitCanBeAddedToForm()
56+
{
57+
$form = $this->factory
58+
->createBuilder('form')
59+
->getForm();
60+
61+
$this->assertSame($form, $form->add('send', 'submit'));
62+
}
5463
}

src/Symfony/Component/HttpKernel/Fragment/InlineFragmentRenderer.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,11 @@ protected function createSubRequest($uri, Request $request)
112112
// Sub-request object will point to localhost as client ip and real client ip
113113
// will be included into trusted header for client ip
114114
try {
115-
$trustedHeaderName = Request::getTrustedHeaderName(Request::HEADER_CLIENT_IP);
116-
$currentXForwardedFor = $request->headers->get($trustedHeaderName, '');
115+
if ($trustedHeaderName = Request::getTrustedHeaderName(Request::HEADER_CLIENT_IP)) {
116+
$currentXForwardedFor = $request->headers->get($trustedHeaderName, '');
117117

118-
$server['HTTP_'.$trustedHeaderName] = ($currentXForwardedFor ? $currentXForwardedFor.', ' : '').$request->getClientIp();
118+
$server['HTTP_'.$trustedHeaderName] = ($currentXForwardedFor ? $currentXForwardedFor.', ' : '').$request->getClientIp();
119+
}
119120
} catch (\InvalidArgumentException $e) {
120121
// Do nothing
121122
}

src/Symfony/Component/HttpKernel/Profiler/ProfilerStorageInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function find($ip, $url, $limit, $method, $start = null, $end = null);
3535
/**
3636
* Reads data associated with the given token.
3737
*
38-
* The method returns false if the token does not exists in the storage.
38+
* The method returns false if the token does not exist in the storage.
3939
*
4040
* @param string $token A token
4141
*

src/Symfony/Component/HttpKernel/Tests/Fragment/InlineFragmentRendererTest.php

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,26 @@ public function testRenderWithObjectsAsAttributesPassedAsObjectsInTheController(
8585
$this->assertEquals('bar', $response->getContent());
8686
}
8787

88+
public function testRenderWithTrustedHeaderDisabled()
89+
{
90+
$trustedHeaderName = Request::getTrustedHeaderName(Request::HEADER_CLIENT_IP);
91+
92+
Request::setTrustedHeaderName(Request::HEADER_CLIENT_IP, '');
93+
94+
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
95+
$kernel
96+
->expects($this->any())
97+
->method('handle')
98+
->with(Request::create('/'))
99+
;
100+
101+
$strategy = new InlineFragmentRenderer($kernel);
102+
103+
$strategy->render('/', Request::create('/'));
104+
105+
Request::setTrustedHeaderName(Request::HEADER_CLIENT_IP, $trustedHeaderName);
106+
}
107+
88108
/**
89109
* @expectedException \RuntimeException
90110
*/
@@ -165,8 +185,11 @@ public function testESIHeaderIsKeptInSubrequest()
165185
{
166186
$expectedSubRequest = Request::create('/');
167187
$expectedSubRequest->headers->set('Surrogate-Capability', 'abc="ESI/1.0"');
168-
$expectedSubRequest->headers->set('x-forwarded-for', array('127.0.0.1'));
169-
$expectedSubRequest->server->set('HTTP_X_FORWARDED_FOR', '127.0.0.1');
188+
189+
if (Request::getTrustedHeaderName(Request::HEADER_CLIENT_IP)) {
190+
$expectedSubRequest->headers->set('x-forwarded-for', array('127.0.0.1'));
191+
$expectedSubRequest->server->set('HTTP_X_FORWARDED_FOR', '127.0.0.1');
192+
}
170193

171194
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
172195
$kernel
@@ -181,6 +204,16 @@ public function testESIHeaderIsKeptInSubrequest()
181204
$request->headers->set('Surrogate-Capability', 'abc="ESI/1.0"');
182205
$strategy->render('/', $request);
183206
}
207+
208+
public function testESIHeaderIsKeptInSubrequestWithTrustedHeaderDisabled()
209+
{
210+
$trustedHeaderName = Request::getTrustedHeaderName(Request::HEADER_CLIENT_IP);
211+
Request::setTrustedHeaderName(Request::HEADER_CLIENT_IP, '');
212+
213+
$this->testESIHeaderIsKeptInSubrequest();
214+
215+
Request::setTrustedHeaderName(Request::HEADER_CLIENT_IP, $trustedHeaderName);
216+
}
184217
}
185218

186219
class Bar {

0 commit comments

Comments
 (0)