Skip to content

Commit 7bb1bf0

Browse files
committed
refactor: Improve parsing of commands for sudo in parseCommandsByLineForSudo
1 parent a1a8f13 commit 7bb1bf0

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

bootstrap/helpers/shared.php

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,14 +1184,16 @@ function check_domain_usage(ServiceApplication|Application|null $resource = null
11841184
function parseCommandsByLineForSudo(Collection $commands, Server $server): array
11851185
{
11861186
$commands = $commands->map(function ($line) {
1187-
if (! str(trim($line))->startsWith([
1188-
'cd',
1189-
'command',
1190-
'echo',
1191-
'true',
1192-
'if',
1193-
'fi',
1194-
])) {
1187+
if (
1188+
! str(trim($line))->startsWith([
1189+
'cd',
1190+
'command',
1191+
'echo',
1192+
'true',
1193+
'if',
1194+
'fi',
1195+
])
1196+
) {
11951197
return "sudo $line";
11961198
}
11971199

@@ -3863,14 +3865,19 @@ function convertComposeEnvironmentToArray($environment)
38633865
{
38643866
$convertedServiceVariables = collect([]);
38653867
if (isAssociativeArray($environment)) {
3868+
// Example: $environment = ['FOO' => 'bar', 'BAZ' => 'qux'];
38663869
if ($environment instanceof Collection) {
38673870
$changedEnvironment = collect([]);
38683871
$environment->each(function ($value, $key) use ($changedEnvironment) {
3869-
$parts = explode('=', $value, 2);
3870-
if (count($parts) === 2) {
3871-
$key = $parts[0];
3872-
$realValue = $parts[1] ?? '';
3873-
$changedEnvironment->put($key, $realValue);
3872+
if (is_numeric($key)) {
3873+
$parts = explode('=', $value, 2);
3874+
if (count($parts) === 2) {
3875+
$key = $parts[0];
3876+
$realValue = $parts[1] ?? '';
3877+
$changedEnvironment->put($key, $realValue);
3878+
} else {
3879+
$changedEnvironment->put($key, $value);
3880+
}
38743881
} else {
38753882
$changedEnvironment->put($key, $value);
38763883
}
@@ -3880,6 +3887,7 @@ function convertComposeEnvironmentToArray($environment)
38803887
}
38813888
$convertedServiceVariables = $environment;
38823889
} else {
3890+
// Example: $environment = ['FOO=bar', 'BAZ=qux'];
38833891
foreach ($environment as $value) {
38843892
$parts = explode('=', $value, 2);
38853893
$key = $parts[0];

0 commit comments

Comments
 (0)