8000 Merge branch '3.4' into 4.0 · symfony/symfony@064acb6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 064acb6

Browse files
committed
Merge branch '3.4' into 4.0
* 3.4: Env var maps to undefined constant. [SecurityBundle] Backport test [Security] fix merge of 2.7 into 2.8 + add test case backport regression test from 3.4 do not mock the container builder or definitions fixed CS [TwigBundle] Register TwigBridge extensions first [WebProfilerBundle] Fix sub request link PhpDocExtractor::getTypes() throws fatal error when type omitted Fix misspelling variable use libsodium to run Argon2i related tests [DI] minor: use a strict comparision in setDecoratedService [HttpKernel] fix FC Follow-on to #25825: Fix edge case in getParameterOption. keep the context when validating forms
2 parents 767b028 + 05a0452 commit 064acb6

File tree

19 files changed

+173
-32
lines changed

19 files changed

+173
-32
lines changed

.travis.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,18 @@ before_install:
133133
- |
134134
# Install extra PHP extensions
135135
if [[ ! $skip ]]; then
136+
([[ $deps ]] || tfold ext.symfony_debug 'cd src/Symfony/Component/Debug/Resources/ext && phpize && ./configure && make && echo extension = $(pwd)/modules/symfony_debug.so >> '"$INI")
137+
tfold ext.apcu tpecl apcu-4.0.11 apcu.so
138+
elif [[ ! $skip && $PHP = 7.* ]]; then
139+
# install libsodium
140+
if [[ ! -e ~/php-ext/$(php -r "echo basename(ini_get('extension_dir'));")/libsodium/sodium.so ]]; then
141+
sudo add-apt-repository ppa:ondrej/php -y
142+
sudo apt-get update -q
143+
sudo apt-get install libsodium-dev -y
144+
fi
145+
136146
tfold ext.apcu tpecl apcu-5.1.6 apcu.so
147+
tfold ext.libsodium tpecl libsodium sodium.so
137148
tfold ext.mongodb tpecl mongodb-1.4.0RC1 mongodb.so
138149
fi
139150

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/yml/argon2i_encoder.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
security:
22
encoders:
3-
JMS\FooBundle\Entity\User6:
3+
JMS\FooBundle\Entity\User7:
44
algorithm: argon2i
55

66
providers:

src/Symfony/Bundle/SecurityBundle/Tests/Functional/UserPasswordEncoderCommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function testEncodePasswordArgon2i()
8686
$this->assertContains('Password encoding succeeded', $output);
8787

8888
$encoder = new Argon2iPasswordEncoder();
89-
preg_match('# Encoded password\s+(\$argon2i\$[\w\d,=\$+\/]+={0,2})\s+#', $output, $matches);
89+
preg_match('# Encoded password\s+(\$argon2id\$[\w\d,=\$+\/]+={0,2})\s+#', $output, $matches);
9090
$hash = $matches[1];
9191
$this->assertTrue($encoder->isPasswordValid($hash, 'password', null));
9292
}
@@ -250,7 +250,7 @@ protected function tearDown()
250250
private function setupArgon2i()
251251
{
252252
putenv('COLUMNS='.(119 + strlen(PHP_EOL)));
253-
$kernel = $this->createKernel(array('test_case' => 'PasswordEncode', 'root_config' => 'argon2i'));
253+
$kernel = $this->createKernel(array('test_case' => 'PasswordEncode', 'root_config' => 'argon2i.yml'));
254254
$kernel->boot();
255255

256256
$application = new Application($kernel);

src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/TwigEnvironmentPass.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,22 @@ public function process(ContainerBuilder $container)
3434
// For instance, global variable definitions must be registered
3535
// afterward. If not, the globals from the extensions will never
3636
// be registered.
37-
$calls = $definition->getMethodCalls();
38-
$definition->setMethodCalls(array());
37+
$currentMethodCalls = $definition->getMethodCalls();
38+
$twigBridgeExtensionsMethodCalls = array();
39+
$othersExtensionsMethodCalls = array();
3940
foreach ($container->findTaggedServiceIds('twig.extension', true) as $id => $attributes) {
40-
$definition->addMethodCall('addExtension', array(new Reference($id)));
41+
$methodCall = array('addExtension', array(new Reference($id)));
42+
$extensionClass = $container->getDefinition($id)->getClass();
43+
44+
if (is_string($extensionClass) && 0 === strpos($extensionClass, 'Symfony\Bridge\Twig\Extension')) {
45+
$twigBridgeExtensionsMethodCalls[] = $methodCall;
46+
} else {
47+
$othersExtensionsMethodCalls[] = $methodCall;
48+
}
49+
}
50+
51+
if (!empty($twigBridgeExtensionsMethodCalls) || !empty($othersExtensionsMethodCalls)) {
52+
$definition->setMethodCalls(array_merge($twigBridgeExtensionsMethodCalls, $othersExtensionsMethodCalls, $currentMethodCalls));
4153
}
42-
$definition->setMethodCalls(array_merge($definition->getMethodCalls(), $calls));
4354
}
4455
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
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\TwigBundle\Tests\DependencyInjection\Compiler;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\Twig\Extension\FormExtension;
16+
use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\TwigEnvironmentPass;
17+
use Symfony\Component\DependencyInjection\ContainerBuilder;
18+
use Symfony\Component\DependencyInjection\Reference;
19+
20+
class TwigEnvironmentPassTest extends TestCase
21+
{
22+
public function testTwigBridgeExtensionsAreRegisteredFirst()
23+
{
24+
$container = new ContainerBuilder();
25+
$twigDefinition = $container->register('twig');
26+
$container->register('other_extension', 'Foo\Bar')
27+
->addTag('twig.extension');
28+
$container->register('twig_bridge_extension', FormExtension::class)
29+
->addTag('twig.extension');
30+
31+
$twigEnvironmentPass = new TwigEnvironmentPass();
32+
$twigEnvironmentPass->process($container);
33+
34+
$methodCalls = $twigDefinition->getMethodCalls();
35+
$this->assertCount(2, $methodCalls);
36+
37+
$twigBridgeExtensionReference = $methodCalls[0][1][0];
38+
$this->assertInstanceOf(Reference::class, $twigBridgeExtensionReference);
39+
$this->assertSame('twig_bridge_extension', (string) $twigBridgeExtensionReference);
40+
41+
$otherExtensionReference = $methodCalls[1][1][0];
42+
$this->assertInstanceOf(Reference::class, $otherExtensionReference);
43+
$this->assertSame('other_extension', (string) $otherExtensionReference);
44+
}
45+
}

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/request.html.twig

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,7 @@
271271
<div class="tab-content">
272272
{% for child in profile.children %}
273273
<h3>
274-
<a href="{{ path('_profiler', { token: child.token }) }}">
275-
{{ helper.set_handler(child.getcollector('request').controller) }}
276-
</a>
274+
{{ helper.set_handler(child.getcollector('request').controller) }}
277275
<small>(token = <a href="{{ path('_profiler', { token: child.token }) }}">{{ child.token }}</a>)</small>
278276
</h3>
279277

src/Symfony/Component/Console/Input/ArgvInput.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,11 @@ public function hasParameterOption($values, $onlyParams = false)
277277
return false;
278278
}
279279
foreach ($values as $value) {
280-
if ($token === $value || 0 === strpos($token, $value.'=')) {
280+
// Options with values:
281+
// For long options, test for '--option=' at beginning
282+
// For short options, test for '-o' at beginning
283+
$leading = 0 === strpos($value, '--') ? $value.'=' : $value;
284+
if ($token === $value || 0 === strpos($token, $leading)) {
281285
return true;
282286
}
283287
}
@@ -301,13 +305,16 @@ public function getParameterOption($values, $default = false, $onlyParams = fals
301305
}
302306

303307
foreach ($values as $value) {
304-
if ($token === $value || 0 === strpos($token, $value.'=')) {
305-
if (false !== $pos = strpos($token, '=')) {
306-
return substr($token, $pos + 1);
307-
}
308-
308+
if ($token === $value) {
309309
return array_shift($tokens);
310310
}
311+
// Options with values:
312+
// For long options, test for '--option=' at beginning
313+
// For short options, test for '-o' at beginning
314+
$leading = 0 === strpos($value, '--') ? $value.'=' : $value;
315+
if (0 === strpos($token, $leading)) {
316+
return substr($token, strlen($leading));
317+
}
311318
}
312319
}
313320

src/Symfony/Component/Console/Input/InputInterface.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public function getFirstArgument();
3333
*
3434
* This method is to be used to introspect the input parameters
3535
* before they have been validated. It must be used carefully.
36+
* Does not necessarily return the correct result for short options
37+
* when multiple flags are combined in the same option.
3638
*
3739
* @param string|array $values The values to look for in the raw parameters (can be an array)
3840
* @param bool $onlyParams Only check real parameters, skip those following an end of options (--) signal
@@ -46,6 +48,8 @@ public function hasParameterOption($values, $onlyParams = false);
4648
*
4749
* This method is to be used to introspect the input parameters
4850
* before they have been validated. It must be used carefully.
51+
* Does not necessarily return the correct result for short options
52+
* when multiple flags are combined in the same option.
4953
*
5054
* @param string|array $values The value(s) to look for in the raw parameters (can be an array)
5155
* @param mixed $default The default value to return if no result is found

src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,10 @@ public function testHasParameterOption()
314314
$input = new ArgvInput(array('cli.php', '-f', 'foo'));
315315
$this->assertTrue($input->hasParameterOption('-f'), '->hasParameterOption() returns true if the given short option is in the raw input');
316316

317+
$input = new ArgvInput(array('cli.php', '-etest'));
318+
$this->asser F438 tTrue($input->hasParameterOption('-e'), '->hasParameterOption() returns true if the given short option is in the raw input');
319+
$this->assertFalse($input->hasParameterOption('-s'), '->hasParameterOption() returns true if the given short option is in the raw input');
320+
317321
$input = new ArgvInput(array('cli.php', '--foo', 'foo'));
318322
$this->assertTrue($input->hasParameterOption('--foo'), '->hasParameterOption() returns true if the given short option is in the raw input');
319323

@@ -339,6 +343,33 @@ public function testHasParameterOptionOnlyOptions()
339343
$this->assertFalse($input->hasParameterOption('--foo', true), '->hasParameterOption() returns false if the given option is in the raw input but after an end of options signal');
340344
}
341345

346+
public function testHasParameterOptionEdgeCasesAndLimitations()
347+
{
348+
$input = new ArgvInput(array('cli.php', '-fh'));
349+
// hasParameterOption does not know if the previous short option, -f,
350+
// takes a value or not. If -f takes a value, then -fh does NOT include
351+
// -h; Otherwise it does. Since we do not know which short options take
352+
// values, hasParameterOption does not support this use-case.
353+
$this->assertFalse($input->hasParameterOption('-h'), '->hasParameterOption() returns true if the given short option is in the raw input');
354+
// hasParameterOption does detect that `-fh` contains `-f`, since
355+
// `-f` is the first short option in the set.
356+
$this->assertTrue($input->hasParameterOption('-f'), '->hasParameterOption() returns true if the given short option is in the raw input');
357+
// The test below happens to pass, although it might make more sense
358+
// to disallow it, and require the use of
359+
// $input->hasParameterOption('-f') && $input->hasParameterOption('-h')
360+
// instead.
361+
$this->assertTrue($input->hasParameterOption('-fh'), '->hasParameterOption() returns true if the given short option is in the raw input');
362+
// In theory, if -fh is supported, then -hf should also work.
363+
// However, this is not supported.
364+
$this->assertFalse($input->hasParameterOption('-hf'), '->hasParameterOption() returns true if the given short option is in the raw input');
365+
366+
$input = new ArgvInput(array('cli.php', '-f', '-h'));
367+
// If hasParameterOption('-fh') is supported for 'cli.php -fh', then
368+
// one might also expect that it should also be supported for
369+
// 'cli.php -f -h'. However, this is not supported.
370+
$this->assertFalse($input->hasParameterOption('-fh'), '->hasParameterOption() returns true if the given short option is in the raw input');
371+
}
372+
342373
public function testToString()
343374
{
344375
$input = new ArgvInput(array('cli.php', '-f', 'foo'));

src/Symfony/Component/DependencyInjection/Definition.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public function getFactory()
128128
*/
129129
public function setDecoratedService($id, $renamedId = null, $priority = 0)
130130
{
131-
if ($renamedId && $id == $renamedId) {
131+
if ($renamedId && $id === $renamedId) {
132132
throw new InvalidArgumentException(sprintf('The decorated service inner name for "%s" must be different than the service name itself.', $id));
133133
}
134134

src/Symfony/Component/DependencyInjection/EnvVarProcessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function getEnv($prefix, $name, \Closure $getEnv)
114114
throw new RuntimeException(sprintf('Env var "%s" maps to undefined constant "%s".', $name, $env));
115115
}
116116

117-
return constant($name);
117+
return constant($env);
118118
}
119119

120120
if ('base64' === $prefix) {

src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ public function validate($form, Constraint $constraint)
113113
? (string) $form->getViewData()
114114
: gettype($form->getViewData());
115115

116+
$this->context->setConstraint($constraint);
116117
$this->context->buildViolation($config->getOption('invalid_message'))
117118
->setParameters(array_replace(array('{{ value }}' => $clientDataAsString), $config->getOption('invalid_message_parameters')))
118119
->setInvalidValue($form->getViewData())
@@ -124,6 +125,7 @@ public function validate($form, Constraint $constraint)
124125

125126
// Mark the form with an error if it contains extra fields
126127
if (!$config->getOption('allow_extra_fields') && count($form->getExtraData()) > 0) {
128+
$this->context->setConstraint($constraint);
127129
$this->context->buildViolation($config->getOption('extra_fields_message'))
128130
->setParameter('{{ extra_fields }}', implode('", "', array_keys($form->getExtraData())))
129131
->setInvalidValue($form->getExtraData())

src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ protected function setUp()
5151
$this->serverParams = $this->getMockBuilder('Symfony\Component\Form\Extension\Validator\Util\ServerParams')->setMethods(array('getNormalizedIniPostMaxSize', 'getContentLength'))->getMock();
5252

5353
parent::setUp();
54+
55+
$this->constraint = new Form();
5456
}
5557

5658
protected function createValidator()

src/Symfony/Component/HttpFoundation/Tests/RequestTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2064,11 +2064,11 @@ public function testMethodSafeChecksCacheable()
20642064
/**
20652065
* @dataProvider methodCacheableProvider
20662066
*/
2067-
public function testMethodCacheable($method, $chacheable)
2067+
public function testMethodCacheable($method, $cacheable)
20682068
{
20692069
$request = new Request();
20702070
$request->setMethod($method);
2071-
$this->assertEquals($chacheable, $request->isMethodCacheable());
2071+
$this->assertEquals($cacheable, $request->isMethodCacheable());
20722072
}
20732073

20742074
public function methodCacheableProvider()

src/Symfony/Component/HttpKernel/Tests/ClientTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,16 @@ public function testFilterResponseSupportsStreamedResponses()
9797
public function testUploadedFile()
9898
{
9999
$source = tempnam(sys_get_temp_dir(), 'source');
100+
file_put_contents($source, '1');
100101
$target = sys_get_temp_dir().'/sf.moved.file';
101102
@unlink($target);
102103

103104
$kernel = new TestHttpKernel();
104105
$client = new Client($kernel);
105106

106107
$files = array(
107-
array('tmp_name' => $source, 'name' => 'original', 'type' => 'mime/original', 'size' => 123, 'error' => UPLOAD_ERR_OK),
108-
new UploadedFile($source, 'original', 'mime/original', 123, UPLOAD_ERR_OK, true),
108+
array('tmp_name' => $source, 'name' => 'original', 'type' => 'mime/original', 'size' => 1, 'error' => UPLOAD_ERR_OK),
109+
new UploadedFile($source, 'original', 'mime/original', 1, UPLOAD_ERR_OK, true),
109110
);
110111

111112
$file = null;
@@ -120,7 +121,7 @@ public function testUploadedFile()
120121

121122
$this->assertEquals('original', $file->getClientOriginalName());
122123
$this->assertEquals('mime/original', $file->getClientMimeType());
123-
$this->assertEquals(< 10000 span class="pl-s">'123', $file->getClientSize());
124+
$this->assertSame(1, $file->getClientSize());
124125
$this->assertTrue($file->isValid());
125126
}
126127

src/Symfony/Component/PropertyInfo/Extractor/PhpDocExtractor.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ public function getTypes($class, $property, array $context = array())
131131
$types = array();
132132
/** @var DocBlock\Tags\Var_|DocBlock\Tags\Return_|DocBlock\Tags\Param $tag */
133133
foreach ($docBlock->getTagsByName($tag) as $tag) {
134-
$types = array_merge($types, $this->phpDocTypeHelper->getTypes($tag->getType()));
134+
if ($tag && null !== $tag->getType()) {
135+
$types = array_merge($types, $this->phpDocTypeHelper->getTypes($tag->getType()));
136+
}
135137
}
136138

137139
if (!isset($types[0])) {

src/Symfony/Component/PropertyInfo/Tests/Extractors/PhpDocExtractorTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ public function testExtract($property, array $type = null, $shortDescription, $l
4040
$this->assertSame($longDescription, $this->extractor->getLongDescription('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', $property));
4141
}
4242

43+
public function testParamTagTypeIsOmitted()
44+
{
45+
$this->assertNull($this->extractor->getTypes(OmittedParamTagTypeDocBlock::class, 'omittedType'));
46+
}
47+
4348
/**
4449
* @dataProvider typesWithCustomPrefixesProvider
4550
*/
@@ -176,3 +181,15 @@ class EmptyDocBlock
176181
{
177182
public $foo;
178183
}
184+
185+
class OmittedParamTagTypeDocBlock
186+
{
187+
/**
188+
* The type is omitted here to ensure that the extractor doesn't choke on missing types.
189+
*
190+
* @param $omittedTagType
191+
*/
192+
public function setOmittedType(array $omittedTagType)
193+
{
194+
}
195+
}

src/Symfony/Component/Security/Http/Firewall/UsernamePasswordFormAuthenticationListener.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,13 @@ protected function attemptAuthentication(Request $request)
7777
}
7878
}
7979

80-
$requestBag = $this->options['post_only'] ? $request->request : $request;
81-
$username = ParameterBagUtils::getParameterBagValue($requestBag, $this->options['username_parameter']);
82-
$password = ParameterBagUtils::getParameterBagValue($requestBag, $this->options['password_parameter']);
80+
if ($this->options['post_only']) {
81+
$username = ParameterBagUtils::getParameterBagValue($request->request, $this->options['username_parameter']);
82+
$password = ParameterBagUtils::getParameterBagValue($request->request, $this->options['password_parameter']);
83+
} else {
84+
$username = ParameterBagUtils::getRequestParameterValue($request, $this->options['username_parameter']);
85+
$password = ParameterBagUtils::getRequestParameterValue($request, $this->options['password_parameter']);
86+
}
8387

8488
if (!\is_string($username) || (\is_object($username) && !\method_exists($username, '__toString'))) {
8589
throw new BadRequestHttpException(sprintf('The key "%s" must be a string, "%s" given.', $this->options['username_parameter'], \gettype($username)));

0 commit comments

Comments
 (0)
0