8000 Merge branch '2.8' into 3.4 · symfony/symfony@05a0452 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 05a0452

Browse files
committed
Merge branch '2.8' into 3.4
* 2.8: [SecurityBundle] Backport test [Security] fix merge of 2.7 into 2.8 + add test case backport regression test from 3.4 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 0c4b32c + 641a46b commit 05a0452

File tree

10 files changed

+75
-17
lines changed

10 files changed

+75
-17
lines changed

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,11 @@ public function hasParameterOption($values, $onlyParams = false)
282282
return false;
283283
}
284284
foreach ($values as $value) {
285-
if ($token === $value || 0 === strpos($token, $value.'=')) {
285+
// Options with values:
286+
// For long options, test for '--option=' at beginning
287+
// For short options, test for '-o' at beginning
288+
$leading = 0 === strpos($value, '--') ? $value.'=' : $value;
289+
if ($token === $value || 0 === strpos($token, $leading)) {
286290
return true;
287291
}
288292
}
@@ -306,13 +310,16 @@ public function getParameterOption($values, $default = false, $onlyParams = fals
306310
}
307311

308312
foreach ($values as $value) {
309-
if ($token === $value || 0 === strpos($token, $value.'=')) {
310-
if (false !== $pos = strpos($token, '=')) {
311-
return substr($token, $pos + 1);
312-
}
313-
313+
if ($token === $value) {
314314
return array_shift($tokens);
315315
}
316+
// Options with values:
317+
// For long options, test for '--option=' at beginning
318+
// For short options, test for '-o' at beginning
319+
$leading = 0 === strpos($value, '--') ? $value.'=' : $value;
320+
if (0 === strpos($token, $leading)) {
321+
return substr($token, strlen($leading));
322+
}
316323
}
317324
}
318325

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->assertTrue($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
@@ -129,7 +129,7 @@ public function getFactory()
129129
*/
130130
public function setDecoratedService($id, $renamedId = null, $priority = 0)
131131
{
132-
if ($renamedId && $id == $renamedId) {
132+
if ($renamedId && $id === $renamedId) {
133133
throw new InvalidArgumentException(sprintf('The decorated service inner name for "%s" must be different than the service name itself.', $id));
134134
}
135135

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
@@ -2148,11 +2148,11 @@ public function testMethodSafeChecksCacheable()
21482148
/**
21492149
* @dataProvider methodCacheableProvider
21502150
*/
2151-
public function testMethodCacheable($method, $chacheable)
2151+
public function testMethodCacheable($method, $cacheable)
21522152
{
21532153
$request = new Request();
21542154
$request->setMethod($method);
2155-
$this->assertEquals($chacheable, $request->isMethodCacheable());
2155+
$this->assertEquals($cacheable, $request->isMethodCacheable());
21562156
}
21572157

21582158
public function methodCacheableProvider()

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ class EmptyDocBlock
185185
class OmittedParamTagTypeDocBlock
186186
{
187187
/**
188+
* The type is omitted here to ensure that the extractor doesn't choke on missing types.
189+
*
188190
* @param $omittedTagType
189191
*/
190192
public function setOmittedType(array $omittedTagType)

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)));

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ public function testHandleWhenUsernameLength($username, $ok)
7777
}
7878

7979
/**
80+
* @dataProvider postOnlyDataProvider
8081
* @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
8182
* @expectedExceptionMessage The key "_username" must be a string, "array" given.
8283
*/
83-
public function testHandleNonStringUsername()
84+
public function testHandleNonStringUsername($postOnly)
8485
{
8586
$request = Request::create('/login_check', 'POST', array('_username' => array()));
8687
$request->setSession($this->getMockBuilder('Symfony\Component\HttpFoundation\Session\SessionInterface')->getMock());
87-
8888
$listener = new UsernamePasswordFormAuthenticationListener(
8989
new TokenStorage(),
9090
$this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')->getMock(),
@@ -93,14 +93,20 @@ public function testHandleNonStringUsername()
9393
'foo',
9494
new DefaultAuthenticationSuccessHandler($httpUtils),
9595
new DefaultAuthenticationFailureHandler($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $httpUtils),
96-
array('require_previous_session' => false)
96+
array('require_previous_session' => false, 'post_only' => $postOnly)
9797
);
98-
9998
$event = new GetResponseEvent($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $request, HttpKernelInterface::MASTER_REQUEST);
100-
10199
$listener->handle($event);
102100
}
103101

102+
public function postOnlyDataProvider()
103+
{
104+
return array(
105+
array(true),
106+
array(false),
107+
);
108+
}
109+
104110
public function getUsernameForLength()
105111
{
106112
return array(

0 commit comments

Comments
 (0)
0