mirror of
https://github.com/coollabsio/coolify.git
synced 2026-03-11 08:55:47 +00:00
fix: preserve docker label values with equals
This commit is contained in:
parent
cb759b2846
commit
28948cc7c8
2 changed files with 34 additions and 6 deletions
|
|
@ -96,21 +96,33 @@ function format_docker_labels_to_json(string|array $rawOutput): Collection
|
|||
if (is_array($rawOutput)) {
|
||||
return collect($rawOutput);
|
||||
}
|
||||
$outputLines = explode(PHP_EOL, $rawOutput);
|
||||
$outputLines = collect(explode(PHP_EOL, $rawOutput))
|
||||
->reject(fn ($line) => empty($line));
|
||||
|
||||
return collect($outputLines)
|
||||
->reject(fn ($line) => empty($line))
|
||||
if ($outputLines->isEmpty()) {
|
||||
return collect([]);
|
||||
}
|
||||
|
||||
return $outputLines
|
||||
->map(function ($outputLine) {
|
||||
$outputArray = explode(',', $outputLine);
|
||||
|
||||
return collect($outputArray)
|
||||
->map(function ($outputLine) {
|
||||
return explode('=', $outputLine);
|
||||
return explode('=', $outputLine, 2);
|
||||
})
|
||||
->mapWithKeys(function ($outputLine) {
|
||||
return [$outputLine[0] => $outputLine[1]];
|
||||
$key = $outputLine[0] ?? null;
|
||||
$value = $outputLine[1] ?? '';
|
||||
|
||||
if (empty($key)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [$key => $value];
|
||||
});
|
||||
})[0];
|
||||
})
|
||||
->first() ?? collect([]);
|
||||
}
|
||||
|
||||
function format_docker_envs_to_json($rawOutput)
|
||||
|
|
|
|||
16
tests/Feature/DockerLabelsToJsonTest.php
Normal file
16
tests/Feature/DockerLabelsToJsonTest.php
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
test('format_docker_labels_to_json preserves equals in values', function () {
|
||||
$rawLabels = 'coolify.config=foo=bar,com.docker.compose.project=coolify';
|
||||
|
||||
$labels = format_docker_labels_to_json($rawLabels);
|
||||
|
||||
expect($labels->get('coolify.config'))->toBe('foo=bar')
|
||||
->and($labels->get('com.docker.compose.project'))->toBe('coolify');
|
||||
});
|
||||
|
||||
test('format_docker_labels_to_json returns empty collection for empty input', function () {
|
||||
$labels = format_docker_labels_to_json('');
|
||||
|
||||
expect($labels->isEmpty())->toBeTrue();
|
||||
});
|
||||
Loading…
Reference in a new issue