Skip to content

Commit 58c2053

Browse files
authored
Fix arguments passed to artisan commands that start with 'env' (#52748)
* Add failing tests * Ensure that there is an equal sign so that argument names starting with 'env' are not matched
1 parent 80cdd87 commit 58c2053

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/Illuminate/Foundation/EnvironmentDetector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ protected function getEnvironmentArgument(array $args)
6565
return $args[$i + 1] ?? null;
6666
}
6767

68-
if (str_starts_with($value, '--env')) {
68+
if (str_starts_with($value, '--env=')) {
6969
return head(array_slice(explode('=', $value), 1));
7070
}
7171
}

tests/Foundation/FoundationEnvironmentDetectorTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,34 @@ public function testConsoleEnvironmentDetectionWithNoValue()
4646
}, ['--env']);
4747
$this->assertSame('foobar', $result);
4848
}
49+
50+
public function testConsoleEnvironmentDetectionDoesNotUseArgumentThatStartsWithEnv()
51+
{
52+
$env = new EnvironmentDetector;
53+
54+
$result = $env->detect(function () {
55+
return 'foobar';
56+
}, ['--envelope=mail']);
57+
$this->assertSame('foobar', $result);
58+
}
59+
60+
public function testConsoleEnvironmentDetectionDoesNotUseArgumentThatStartsWithEnvSeparatedWithSpace()
61+
{
62+
$env = new EnvironmentDetector;
63+
64+
$result = $env->detect(function () {
65+
return 'foobar';
66+
}, ['--envelope', 'mail']);
67+
$this->assertSame('foobar', $result);
68+
}
69+
70+
public function testConsoleEnvironmentDetectionDoesNotUseArgumentThatStartsWithEnvWithNoValue()
71+
{
72+
$env = new EnvironmentDetector;
73+
74+
$result = $env->detect(function () {
75+
return 'foobar';
76+
}, ['--envelope']);
77+
$this->assertSame('foobar', $result);
78+
}
4979
}

0 commit comments

Comments
 (0)