Skip to content

Commit

Permalink
bug #25487 [Console] Fix a bug when passing a letter that could be an…
Browse files Browse the repository at this point in the history
… alias (Simperfit)

This PR was merged into the 2.7 branch.

Discussion
----------

[Console] Fix a bug when passing a letter that could be an alias

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no <!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks?    | no
| Deprecations? | no <!-- don't forget to update UPGRADE-*.md files -->
| Tests pass?   | yes
| Fixed tickets | see #24987 (comment)
| License       | MIT
| Doc PR        |

Fixing the global in console commands I've introduced a bug where when you pass -e=test it finds it a --shell, this fix the wrong behaviour.
cc @Zwartpet

Commits
-------

a8871de [Console] Fix a bug when passing a letter that could be an alias
  • Loading branch information
fabpot committed Dec 14, 2017
2 parents e77545a + a8871de commit ccc9367
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Symfony/Component/Console/Input/ArgvInput.php
Expand Up @@ -284,6 +284,8 @@ public function hasParameterOption($values)
}

if (0 === strpos($token, '-') && 0 !== strpos($token, '--')) {
$noValue = explode('=', $token);
$token = $noValue[0];
$searchableToken = str_replace('-', '', $token);
$searchableValue = str_replace('-', '', $value);
if ('' !== $searchableToken && '' !== $searchableValue && false !== strpos($searchableToken, $searchableValue)) {
Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php
Expand Up @@ -299,6 +299,9 @@ public function testHasParameterOption()
$input = new ArgvInput(array('cli.php', '-fh'));
$this->assertTrue($input->hasParameterOption('-fh'), '->hasParameterOption() returns true if the given short option is in the raw input');

$input = new ArgvInput(array('cli.php', '-e=test'));
$this->assertFalse($input->hasParameterOption('-s'), '->hasParameterOption() returns true if the given short option is in the raw input');

$input = new ArgvInput(array('cli.php', '--foo', 'foo'));
$this->assertTrue($input->hasParameterOption('--foo'), '->hasParameterOption() returns true if the given short option is in the raw input');

Expand Down

0 comments on commit ccc9367

Please sign in to comment.