Compare commits

...

1 Commits

Author SHA1 Message Date
Lance Pioch
ab4eadec32 Fix Exporting an egg in yaml format (#2172) 2026-02-07 08:10:00 -05:00
2 changed files with 67 additions and 1 deletions

View File

@@ -92,7 +92,7 @@ class EggExporterService
return $this->yamlExport($decoded);
}
return str_replace(["\r\n", '\\r\\n', '\\n'], "\n", $data);
return str_replace("\r\n", "\n", $data);
}
if (is_array($data)) {

View File

@@ -0,0 +1,66 @@
<?php
namespace App\Tests\Unit\Services\Eggs;
use App\Services\Eggs\Sharing\EggExporterService;
use PHPUnit\Framework\TestCase;
class EggExporterServiceTest extends TestCase
{
private EggExporterService $service;
protected function setUp(): void
{
parent::setUp();
$this->service = new EggExporterService();
}
public function test_yaml_export_preserves_literal_backslash_n_in_scripts(): void
{
$script = <<<'BASH'
if [[ "${STEAM_USER}" == "" ]] || [[ "${STEAM_PASS}" == "" ]]; then
echo -e "steam user is not set.\n"
echo -e "Using anonymous user.\n"
STEAM_USER=anonymous
STEAM_PASS=""
STEAM_AUTH=""
else
echo -e "user set to ${STEAM_USER}"
fi
BASH;
$result = $this->callYamlExport($script);
$this->assertStringContainsString('echo -e "steam user is not set.\n"', $result);
$this->assertStringContainsString('echo -e "Using anonymous user.\n"', $result);
}
public function test_yaml_export_preserves_literal_backslash_r_backslash_n(): void
{
$script = 'echo -e "line ending\\r\\n"';
$result = $this->callYamlExport($script);
$this->assertSame($script, $result);
}
public function test_yaml_export_normalizes_real_crlf_to_lf(): void
{
$script = "line one\r\nline two\r\nline three";
$result = $this->callYamlExport($script);
$this->assertSame("line one\nline two\nline three", $result);
}
/**
* Call the protected yamlExport method via reflection.
*/
private function callYamlExport(mixed $data): mixed
{
$reflection = new \ReflectionMethod($this->service, 'yamlExport');
return $reflection->invoke($this->service, $data);
}
}