From e56d0dc3505664f0c9c972c59cbed58df3e8fc4c Mon Sep 17 00:00:00 2001 From: Will Rowe Date: Wed, 11 Sep 2024 19:41:24 -0400 Subject: [PATCH 1/2] Add failing tests --- .../FoundationEnvironmentDetectorTest.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/Foundation/FoundationEnvironmentDetectorTest.php b/tests/Foundation/FoundationEnvironmentDetectorTest.php index d302c375bf50..c06a8ac386dd 100644 --- a/tests/Foundation/FoundationEnvironmentDetectorTest.php +++ b/tests/Foundation/FoundationEnvironmentDetectorTest.php @@ -46,4 +46,34 @@ public function testConsoleEnvironmentDetectionWithNoValue() }, ['--env']); $this->assertSame('foobar', $result); } + + public function testConsoleEnvironmentDetectionDoesNotUseArgumentThatStartsWithEnv() + { + $env = new EnvironmentDetector; + + $result = $env->detect(function () { + return 'foobar'; + }, ['--envelope=mail']); + $this->assertSame('foobar', $result); + } + + public function testConsoleEnvironmentDetectionDoesNotUseArgumentThatStartsWithEnvSeparatedWithSpace() + { + $env = new EnvironmentDetector; + + $result = $env->detect(function () { + return 'foobar'; + }, ['--envelope', 'mail']); + $this->assertSame('foobar', $result); + } + + public function testConsoleEnvironmentDetectionDoesNotUseArgumentThatStartsWithEnvWithNoValue() + { + $env = new EnvironmentDetector; + + $result = $env->detect(function () { + return 'foobar'; + }, ['--envelope']); + $this->assertSame('foobar', $result); + } } From 0e07f64a6da112cf6f3b5577aed9b89c6e16430d Mon Sep 17 00:00:00 2001 From: Will Rowe Date: Wed, 11 Sep 2024 19:45:22 -0400 Subject: [PATCH 2/2] Ensure that there is an equal sign so that argument names starting with 'env' are not matched --- src/Illuminate/Foundation/EnvironmentDetector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Foundation/EnvironmentDetector.php b/src/Illuminate/Foundation/EnvironmentDetector.php index b2747bc6800e..8fa61bd2e983 100644 --- a/src/Illuminate/Foundation/EnvironmentDetector.php +++ b/src/Illuminate/Foundation/EnvironmentDetector.php @@ -65,7 +65,7 @@ protected function getEnvironmentArgument(array $args) return $args[$i + 1] ?? null; } - if (str_starts_with($value, '--env')) { + if (str_starts_with($value, '--env=')) { return head(array_slice(explode('=', $value), 1)); } }