8000 Merge branch '2.7' into 2.8 · symfony/symfony@641a46b · GitHub
[go: up one dir, main page]

Skip to content

Commit 641a46b

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: [SecurityBundle] Backport test Fix misspelling variable [DI] minor: use a strict comparision in setDecoratedService Follow-on to #25825: Fix edge case in getParameterOption. keep the context when validating forms
2 parents 36e79f7 + b22f1df commit 641a46b

File tree

8 files changed

+56
-12
lines changed

8 files changed

+56
-12
lines changed

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,11 @@ public function hasParameterOption($values)
281281

282282
foreach ($this->tokens as $token) {
283283
foreach ($values as $value) {
284-
if ($token === $value || 0 === strpos($token, $value.'=')) {
284+
// Options with values:
285+
// For long options, test for '--option=' at beginning
286+
// For short options, test for '-o' at beginning
287+
$leading = 0 === strpos($value, '--') ? $value.'=' : $value;
288+
if ($token === $value || 0 === strpos($token, $leading)) {
285289
return true;
286290
}
287291
}
@@ -302,13 +306,16 @@ public function getParameterOption($values, $default = false)
302306
$token = array_shift($tokens);
303307

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

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
*
@@ -45,6 +47,8 @@ public function hasParameterOption($values);
4547
*
4648
* This method is to be used to introspect the input parameters
4749
* before they have been validated. It must be used carefully.
50+
* Does not necessarily return the correct result for short options
51+
* when multiple flags are combined in the same option.
4852
*
4953
* @param string|array $values The value(s) to look for in the raw parameters (can be an array)
5054
* @param mixed $default The default value to return if no result is found

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

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

299+
$input = new ArgvInput(array('cli.php', '-etest'));
300+
$this->assertTrue($input->hasParameterOption('-e'), '->hasParameterOption() returns true if the given short option is in the raw input');
301+
$this->assertFalse($input->hasParameterOption('-s'), '->hasParameterOption() returns true if the given short option is in the raw input');
302+
299303
$input = new ArgvInput(array('cli.php', '--foo', 'foo'));
300304
$this->assertTrue($input->hasParameterOption('--foo'), '->hasParameterOption() returns true if the given short option is in the raw input');
301305

@@ -306,6 +310,33 @@ public function testHasParameterOption()
306310
$this->assertTrue($input->hasParameterOption('--foo'), '->hasParameterOption() returns true if the given option with provided value is in the raw input');
307311
}
308312

313+
public function testHasParameterOptionEdgeCasesAndLimitations()
314+
{
315+
$input = new ArgvInput(array('cli.php', '-fh'));
316+
// hasParameterOption does not know if the previous short option, -f,
317+
// takes a value or not. If -f takes a value, then -fh does NOT include
318+
// -h; Otherwise it does. Since we do not know which short options take
319+
// values, hasParameterOption does not support this use-case.
320+
$this->assertFalse($input->hasParameterOption('-h'), '->hasParameterOption() returns true if the given short option is in the raw input');
321+
// hasParameterOption does detect that `-fh` contains `-f`, since
322+
// `-f` is the first short option in the set.
323+
$this->assertTrue($input->hasParameterOption('-f'), '->hasParameterOption() returns true if the given short option is in the raw input');
324+
// The test below happens to pass, although it might make more sense
325+
// to disallow it, and require the use of
326+
// $input->hasParameterOption('-f') && $input->hasParameterOption('-h')
327+
// instead.
328+
$this->assertTrue($input->hasParameterOption('-fh'), '->hasParameterOption() returns true if the given short option is in the raw input');
329+
// In theory, if -fh is supported, then -hf should also work.
330+
// However, this is not supported.
331+
$this->assertFalse($input->hasParameterOption('-hf'), '->hasParameterOption() returns true if the given short option is in the raw input');
332+
333+
$input = new ArgvInput(array('cli.php', '-f', '-h'));
334+
// If hasParameterOption('-fh') is supported for 'cli.php -fh', then
335+
// one might also expect that it should also be supported for
336+
// 'cli.php -f -h'. However, this is not supported.
337+
$this->assertFalse($input->hasParameterOption('-fh'), '->hasParameterOption() returns true if the given short option is in the raw input');
338+
}
339+
309340
public function testToString()
310341
{
311342
$input = new ArgvInput(array('cli.php', '-f', 'foo'));
@@ -327,6 +358,7 @@ public function testGetParameterOptionEqualSign($argv, $key, $expected)
327358
public function provideGetParameterOptionValues()
328359
{
329360
return array(
361+
array(array('app/console', 'foo:bar', '-edev'), '-e', 'dev'),
330362
array(array('app/console', 'foo:bar', '-e', 'dev'), '-e', 'dev'),
331363
array(array('app/console', 'foo:bar', '--env=dev'), '--env', 'dev'),
332364
array(array('app/console', 'foo:bar', '-e', 'dev'), array('-e', '--env'), 'dev'),

src/Symfony/Component/DependencyInjection/Definition.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public function setFactoryMethod($factoryMethod)
152152
*/
153153
public function setDecoratedService($id, $renamedId = null, $priority = 0)
154154
{
155-
if ($renamedId && $id == $renamedId) {
155+
if ($renamedId && $id === $renamedId) {
156156
throw new \InvalidArgumentException(sprintf('The decorated service inner name for "%s" must be different than the service name itself.', $id));
157157
}
158158

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ public function validate($form, Constraint $constraint)
139139
: gettype($form->getViewData());
140140

141141
if ($this->context instanceof ExecutionContextInterface) {
142+
$this->context->setConstraint($constraint);
142143
$this->context->buildViolation($config->getOption('invalid_message'))
143144
->setParameters(array_replace(array('{{ value }}' => $clientDataAsString), $config->getOption('invalid_message_parameters')))
144145
->setInvalidValue($form->getViewData())
@@ -159,6 +160,7 @@ public function validate($form, Constraint $constraint)
159160
// Mark the form with an error if it contains extra fields
160161
if (!$config->getOption('allow_extra_fields') && count($form->getExtraData()) > 0) {
161162
if ($this->context instanceof ExecutionContextInterface) {
163+
$this->context->setConstraint($constraint);
162164
$this->context->buildViolation($config->getOption('extra_fields_message'))
163165
->setParameter('{{ extra_fields }}', implode('", "', array_keys($form->getExtraData())))
164166
->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
@@ -53,6 +53,8 @@ protected function setUp()
5353
$this->serverParams = $this->getMockBuilder('Symfony\Component\Form\Extension\Validator\Util\ServerParams')->setMethods(array('getNormalizedIniPostMaxSize', 'getContentLength'))->getMock();
5454

5555
parent::setUp();
56+
57+
$this->constraint = new Form();
5658
}
5759

5860
protected function getApiVersion()

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,11 +2031,11 @@ public function testMethodSafeChecksCacheable()
20312031
/**
20322032
* @dataProvider methodCacheableProvider
20332033
*/
2034-
public function testMethodCacheable($method, $chacheable)
2034+
public function testMethodCacheable($method, $cacheable)
20352035
{
20362036
$request = new Request();
20372037
$request->setMethod($method);
2038-
$this->assertEquals($chacheable, $request->isMethodCacheable());
2038+
$this->assertEquals($cacheable, $request->isMethodCacheable());
20392039
}
20402040

20412041
public function methodCacheableProvider()

src/Symfony/Component/Security/Http/Tests/Firewall/UsernamePasswordFormAuthenticationListenerTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ public function testHandleNonStringUsername($postOnly)
8585
{
8686
$request = Request::create('/login_check', 'POST', array('_username' => array()));
8787
$request->setSession($this->getMockBuilder('Symfony\Component\HttpFoundation\Session\SessionInterface')->getMock());
88-
8988
$listener = new UsernamePasswordFormAuthenticationListener(
9089
new TokenStorage(),
9190
$this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')->getMock(),
@@ -96,9 +95,7 @@ public function testHandleNonStringUsername($postOnly)
9695
new DefaultAuthenticationFailureHandler($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $httpUtils),
9796
array('require_previous_session' => false, 'post_only' => $postOnly)
9897
);
99-
10098
$event = new GetResponseEvent($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $request, HttpKernelInterface::MASTER_REQUEST);
101-
10299
$listener->handle($event);
103100
}
104101

0 commit comments

Comments
 (0)
0