From 3da7f5a5a5f1e80803c8bfa861f3fa80ed6d9de1 Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Mon, 24 Aug 2026 00:25:55 +0200 Subject: [PATCH] fix(docker): handle commas in container label values (#11477) --- bootstrap/helpers/docker.php | 10 ++++++---- tests/Unit/Api/LogEndpointHelpersTest.php | 12 ++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/bootstrap/helpers/docker.php b/bootstrap/helpers/docker.php index d152ba58f..00300d26a 100644 --- a/bootstrap/helpers/docker.php +++ b/bootstrap/helpers/docker.php @@ -166,11 +166,13 @@ function format_docker_labels_to_json(string|array $rawOutput): Collection $outputArray = explode(',', $outputLine); return collect($outputArray) - ->map(function ($outputLine) { - return explode('=', $outputLine); - }) ->mapWithKeys(function ($outputLine) { - return [$outputLine[0] => $outputLine[1]]; + $label = explode('=', $outputLine, 2); + if (count($label) !== 2) { + return []; + } + + return [$label[0] => $label[1]]; }); })[0]; } diff --git a/tests/Unit/Api/LogEndpointHelpersTest.php b/tests/Unit/Api/LogEndpointHelpersTest.php index a899669d6..c4173bd69 100644 --- a/tests/Unit/Api/LogEndpointHelpersTest.php +++ b/tests/Unit/Api/LogEndpointHelpersTest.php @@ -94,6 +94,18 @@ ->toBe(['first', 'third']); }); +it('filters service containers when another Docker label contains commas', function () { + $containers = collect([ + [ + 'ID' => 'app', + 'Labels' => 'traefik.http.routers.app.rule=Host(`one.example.com`,`two.example.com`),coolify.name=app-service-uuid', + ], + ]); + + expect(filterServiceSubContainersByName($containers, 'app-service-uuid')->pluck('ID')->all()) + ->toBe(['app']); +}); + it('does not interpolate the requested service name into the docker ps shell command', function () { $source = file_get_contents(__DIR__.'/../../../bootstrap/helpers/docker.php');