8000 bug #26156 Fixes #26136: Avoid emitting warning in hasParameterOption… · symfony/symfony@9d3d237 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9d3d237

Browse files
committed
bug #26156 Fixes #26136: Avoid emitting warning in hasParameterOption() (greg-1-anderson)
This PR was squashed before being merged into the 2.7 branch (closes #26156). Discussion ---------- Fixes #26136: Avoid emitting warning in hasParameterOption() | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #26136 | License | MIT | Doc PR | n/a When hasParameterOption / getParameterOption is passed invalid parameters, a warning may be emitted. While the root cause of the warning is an invalid parameter supplied by the caller, earlier versions of Symfony accepted these parameters, which were effectively ignored. In the context of these methods, what I mean by "invalid parameter" is an empty string, which is the correct datatype, but is not ever a useful thing to provide to these methods. Since empty strings here did not cause a problem in previous versions, and since Symfony is used by all sorts of projects for all sorts of purposes, it seems best to continue to be flexible about the parameters accepted by Symfony APIs. Commits ------- b32fdf1 Fixes #26136: Avoid emitting warning in hasParameterOption()
2 parents 4fbe1d4 + b32fdf1 commit 9d3d237

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ public function hasParameterOption($values)
283283
// For long options, test for '--option=' at beginning
284284
// For short options, test for '-o' at beginning
285285
$leading = 0 === strpos($value, '--') ? $value.'=' : $value;
286-
if ($token === $value || 0 === strpos($token, $leading)) {
286+
if ($token === $value || '' !== $leading && 0 === strpos($token, $leading)) {
287287
return true;
288288
}
289289
}
@@ -311,7 +311,7 @@ public function getParameterOption($values, $default = false)
311311
// For long options, test for '--option=' at beginning
312312
// For short options, test for '-o' at beginning
313313
$leading = 0 === strpos($value, '--') ? $value.'=' : $value;
314-
if (0 === strpos($token, $leading)) {
314+
if ('' !== $leading && 0 === strpos($token, $leading)) {
315315
return substr($token, strlen($leading));
316316
}
317317
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,21 @@ public function testHasParameterOptionEdgeCasesAndLimitations()
337337
$this->assertFalse($input->hasParameterOption('-fh'), '->hasParameterOption() returns true if the given short option is in the raw input');
338338
}
339339

340+
public function testNoWarningOnInvalidParameterOption()
341+
{
342+
$input = new ArgvInput(array('cli.php', '-edev'));
343+
344+
// Control.
345+
$this->assertTrue($input->hasParameterOption(array('-e', '')));
346+
// No warning is thrown if https://github.com/symfony/symfony/pull/26156 is fixed
347+
$this->assertFalse($input->hasParameterOption(array('-m', '')));
348+
349+
// Control.
350+
$this->assertEquals('dev', $input->getParameterOption(array('-e', '')));
351+
// No warning is thrown if https://github.com/symfony/symfony/pull/26156 is fixed
352+
$this->assertFalse($input->getParameterOption(array('-m', '')));
353+
}
354+
340355
public function testToString()
341356
{
342357
$input = new ArgvInput(array('cli.php', '-f', 'foo'));

0 commit comments

Comments
 (0)
0