-
-
Notifications
You must be signed in to change notification settings - Fork 39
Route does not match double-dash flag #9
Comments
What OS are you observing this on? We have used these flags successfully on One note: if the glad should allow an argument, you need to use special
I suggest looking at the tests,
Originally posted by @weierophinney at zendframework/zend-console#6 (comment) |
I forgot to test with real application. The problem only occurs during unit tests for my controller. It is caused by the command line parser regex in AbstractControllerTestCase::run(): preg_match_all('/(--\S+[= ]"[^\s"]*\s*[^\s"]*")|(--\S+=\S+|--\S+\s\S+|\S+)/', $url, $matches); If I dispatch "arg --flag", the command line gets broken down correctly:
but with "--flag arg" I get:
This would be correct in case of value parameters, but not with simple flags. But even with value parameters, this would not work as documented in practice, as demonstrated by this simple script: <?php
var_dump($_SERVER['argv']); Run it with given arguments:
The arguments are passed according to my route specification, which is why the script works as expected when run from the command line, but the unit test fails. Out of curiosity, I changed the route to "--flag=". It turns out that "--flag=arg" works as expected, but "--flag arg" is still treated as separate parameters due to the way the OS parses command lines (I ran it on Linux BTW). So either the request params must be concatenated if argv contains a single "--flag" instead of "--flag=arg", or the "--flag arg" variant should be removed from the documentation. The command line parser in AbstractControllerTestCase needs to be fixed too. I doubt that a single regex will be able to handle all edge cases the same way as the OS does, like escaped quotes. For complex command lines that get parsed incorrectly, it would be nice to pass parameters as an array in the third argument to dispatch(), but currently this gets unconditionally replaced with the parsed command line for console tests. Originally posted by @hschletz at zendframework/zend-console#6 (comment) |
|
This is my simple route definition:
Only "-f" and "-flag" match, "--flag" does not. According to the documentation, "--flag" should match, which would also follow common conventions.
Originally posted by @hschletz at zendframework/zend-console#6
The text was updated successfully, but these errors were encountered: