symfony: [Console] ArgvInput - Short command input using incorrect environment name
Q | A |
---|---|
Bug report? | yes |
Feature request? | no |
BC Break report? | no |
RFC? | no |
Symfony version | 3.4.5-DEV |
There appears to be a bug here, but I haven’t been able to figure out a solution.
The phpunit tests pass.
If I run bin/console cac:cl -e=dev
I’m seeing:
PHP Warning: strpos(): Empty needle in /var/www/api.codereviewvideos.dev/vendor/symfony/symfony/src/Symfony/Component/Console/Input/ArgvInput.php on line 291
PHP Stack trace:
PHP 1. {main}() /var/www/api.codereviewvideos.dev/bin/console:0
PHP 2. Symfony\Component\Console\Input\ArgvInput->hasParameterOption() /var/www/api.codereviewvideos.dev/bin/console:21
PHP 3. strpos() /var/www/api.codereviewvideos.dev/vendor/symfony/symfony/src/Symfony/Component/Console/Input/ArgvInput.php:291
The bigger issue is:
In FileLocator.php line 44:
The file "/var/www/api.codereviewvideos.dev/app/config/config_=dev.yml" does not exist.
The =dev
bit being the problem.
I tracked this down to the change below in getParameterOption
.
return substr($token, strlen($leading));
Looking at the old code:
return substr($token, $pos + 1);
If I change to:
return substr($token, strlen($leading) + 1);
Then the command completes - but the strpos
warnings remain.
I added the following just before the new return
on line 321:
\Doctrine\Common\Util\Debug::dump([
'value' => $value,
'token' => $token,
'0 === strpos($value, "--")' => 0 === strpos($value, '--'),
'leading' => $leading,
'strlen($leading)' => strlen($leading),
'substr($token, strlen($leading))' => substr($token, strlen($leading) + 1),
]);
If I e.g. run the cache:clear
command again I see:
array (size=6)
'value' => string '-e' (length=2)
'token' => string '-e=dev' (length=6)
'0 === strpos($value, "--")' => boolean false
'leading' => string '-e' (length=2)
'strlen($leading)' => int 2
'substr($token, strlen($leading))' => string 'dev' (length=3)
Looks good.
Now if I run the tests I see 8 failures (provideGetParameterOptionValues
) e.g:
8) Symfony\Component\Console\Tests\Input\ArgvInputTest::testGetParameterOptionEqualSign with data set #13 (array('app/console', 'foo:bar', '--', '--env=dev'), '--env', false, 'dev')
->getParameterOption() returns the expected value
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'dev'
+'ev'
One extra thing, this only affects the short options (-e=dev
), using the longer form (--env=dev
) does not trigger this issue. However, the strpos(): Empty needle
issue occurs for both long and short form.
Sorry I haven’t been able to figure this out, but I hope this helps in some way in tracking down the root cause. Thank you for your time.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 16 (11 by maintainers)
Commits related to this issue
- Fixes #26136: Avoid emitting warning when hasParameterOption / getParameterOption is passed invalid parameters. — committed to greg-1-anderson/symfony by greg-1-anderson 6 years ago
- minor #1128 Improve the console script (stof) This PR was merged into the 3.4 branch. Discussion ---------- Improve the console script - look for the `--env` and `--no-debug` only before a `--` se... — committed to symfony/symfony-standard by stof 6 years ago
- Fixes #26136: Avoid emitting warning in hasParameterOption() — committed to symfony/symfony by greg-1-anderson 6 years ago
- 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 #... — committed to symfony/symfony by fabpot 6 years ago
- Merge branch '2.7' into 2.8 * 2.7: Clean calls to http_build_query() [HttpFoundation] Fix missing "throw" in JsonResponse Improve the documentation of Suppress warning from sapi_windows_vt100... — committed to symfony/symfony by nicolas-grekas 6 years ago
- Merge branch '2.8' into 3.4 * 2.8: Another PR template tweak [PropertyInfo] ReflectionExtractor: give a chance to other extractors if no properties Clean calls to http_build_query() [WebProfi... — committed to symfony/symfony by nicolas-grekas 6 years ago
- Merge branch '3.4' into 4.0 * 3.4: [Translation] Process multiple segments within a single unit. Document the container.autowiring.strict_mode option fix custom radios/inputs for checkbox/radio... — committed to symfony/symfony by nicolas-grekas 6 years ago
- Merge branch '4.0' * 4.0: [Translation] Process multiple segments within a single unit. Document the container.autowiring.strict_mode option fix custom radios/inputs for checkbox/radio type A... — committed to symfony/symfony by nicolas-grekas 6 years ago
- Merge branch '4.0' * 4.0: [Translation] Process multiple segments within a single unit. Document the container.autowiring.strict_mode option fix custom radios/inputs for checkbox/radio type A... — committed to sandergo90/symfony by nicolas-grekas 6 years ago
Good suggestions, @benbor. See https://github.com/symfony/symfony-docs/pull/9387 and https://github.com/symfony/symfony/issues/26378.
The changelog has already gone out; perhaps someone can still update that retroactively, though.
Hi guys. @greg-1-anderson I agree with your
but, this case had worked before this fix was merged. At now all commands witch called with
-e=prod
are broken (fyi: with very unusual error Parse error: syntax error, unexpected ‘=’, expecting ‘,’ or ‘)’ in /symfony/var/cache/=prod/src=prodDebugProjectContainer.php:5), so it hard to understand what happens. Console Input documentation doesn’t have any notes about that. Also release changelog doesn’t have any information about BC break.I propose the following:
cc @nicolas-grekas
Ok - really sorry, as I say, not looked into this at all as of yet. I have a real life issue that’s taking precedence currently. I have some 2.x projects around which I will try this on and update. Sorry again for the delay.
Chris
@Simperfit We need to fix that bug where it has been introduced (2.7), new deprecations cannot be added there. If you think something is buggy and should go away in the next major, please consider opening a dedicated discussion.
@codereviewvideos I think that the root bug is here:
https://github.com/codereviewvideos/lets-explore-symfony-4/blob/9cd23e3387a563c03504a8fe8addcd71e10b5b68/bin/console#L27
Is there any reason that you need to pass an empty string as the last element to the parameter to
hasParameterOption()
? You should not get the warning above if you remove this entry, and test only for--no-debug
.That said, I think it would be reasonable to fix up Symfony so that it does not emit a warning when an empty string is passed to the
hasParameterOption()
argument array, as it did not warn in this way in previous releases.