Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

fix(compose): strip UTF-8 BOM before parsing Docker Compose YAML (#12223)

Andras Bacsai54315b10e554
diff --git a/bootstrap/helpers/parsers.php b/bootstrap/helpers/parsers.php
index 21f0d7326d..66330d9d09 100644
--- a/bootstrap/helpers/parsers.php
+++ b/bootstrap/helpers/parsers.php
@@ -26,6 +26,9 @@ use Symfony\Component\Yaml\Yaml;
*/
function parseDockerComposeYaml(string $compose): mixed
{
+ // Editors on Windows can save files with a UTF-8 BOM, which Symfony YAML keeps in the first key.
+ $compose = preg_replace('/^\xEF\xBB\xBF/', '', $compose);
+
return Yaml::parse($compose, maxAliasesForCollections: Application::MAX_DOCKER_COMPOSE_COLLECTION_ALIASES);
}
diff --git a/tests/Unit/DockerComposeByteOrderMarkTest.php b/tests/Unit/DockerComposeByteOrderMarkTest.php
new file mode 100644
index 0000000000..50f94b9812
--- /dev/null
+++ b/tests/Unit/DockerComposeByteOrderMarkTest.php
@@ -0,0 +1,17 @@
+<?php
+
+use Tests\TestCase;
+
+uses(TestCase::class);
+
+it('parses a Docker Compose file that starts with a UTF-8 byte order mark', function () {
+ $compose = "\xEF\xBB\xBFservices:\n web:\n image: nginx:alpine\n";
+
+ expect(parseDockerComposeYaml($compose))->toBe([
+ 'services' => [
+ 'web' => ['image' => 'nginx:alpine'],
+ ],
+ ]);
+
+ validateDockerComposeForInjection($compose);
+});