Skip to content

Commit

Permalink
Allow dashes in the CLI segment. Fixes #3205
Browse files Browse the repository at this point in the history
  • Loading branch information
michalsn committed Jul 3, 2020
1 parent dbadbaa commit f1ac24c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion system/CLI/CLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion system/HTTP/CLIRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions tests/system/CLI/CLITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion tests/system/HTTP/CLIRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down

0 comments on commit f1ac24c

Please sign in to comment.