diff --git a/system/CLI/CLI.php b/system/CLI/CLI.php index fcbbf429b043..97e8f4a0b53d 100644 --- a/system/CLI/CLI.php +++ b/system/CLI/CLI.php @@ -868,7 +868,7 @@ protected static function parseCommandLine() { // If there's no '-' at the beginning of the argument // then add it to our segments. - if (mb_strpos($_SERVER['argv'][$i], '-') === false) + if (mb_strpos($_SERVER['argv'][$i], '-') !== 0) { static::$segments[] = $_SERVER['argv'][$i]; continue; diff --git a/system/HTTP/CLIRequest.php b/system/HTTP/CLIRequest.php index f9c48388483e..f5b624d61824 100644 --- a/system/HTTP/CLIRequest.php +++ b/system/HTTP/CLIRequest.php @@ -223,7 +223,7 @@ protected function parseCommand() { // If there's no '-' at the beginning of the argument // then add it to our segments. - if (! $options_found && strpos($argv[$i], '-') === false) + if (! $options_found && strpos($argv[$i], '-') !== 0) { $this->segments[] = filter_var($argv[$i], FILTER_SANITIZE_STRING); continue; diff --git a/tests/system/CLI/CLITest.php b/tests/system/CLI/CLITest.php index 2c6c844051ae..6c6302d504f5 100644 --- a/tests/system/CLI/CLITest.php +++ b/tests/system/CLI/CLITest.php @@ -283,14 +283,15 @@ public function testParseCommandMixed() '-parm', 'pvalue', 'd2', + 'da-sh', ]; - $_SERVER['argc'] = 7; + $_SERVER['argc'] = 8; CLI::init(); $this->assertEquals(null, CLI::getSegment(7)); $this->assertEquals('b', CLI::getSegment(1)); $this->assertEquals('c', CLI::getSegment(2)); $this->assertEquals('d', CLI::getSegment(3)); - $this->assertEquals(['b', 'c', 'd', 'd2'], CLI::getSegments()); + $this->assertEquals(['b', 'c', 'd', 'd2', 'da-sh'], CLI::getSegments()); } public function testParseCommandOption() diff --git a/tests/system/HTTP/CLIRequestTest.php b/tests/system/HTTP/CLIRequestTest.php index 3324834f56cc..e161fcac2a78 100644 --- a/tests/system/HTTP/CLIRequestTest.php +++ b/tests/system/HTTP/CLIRequestTest.php @@ -164,7 +164,7 @@ public function testParsingMalformed() $this->request = new CLIRequest(new App()); $expectedOptions = '-foo bar -baz "queue some stuff"'; - $expectedPath = 'users/21'; + $expectedPath = 'users/21/pro-file'; $this->assertEquals($expectedOptions, $this->request->getOptionString()); $this->assertEquals($expectedPath, $this->request->getPath()); }