2021-04-24 16:39:56 -07:00
|
|
|
<?php
|
|
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace Pterodactyl\Tests\Pest\Unit\Helpers\EnvironmentWriterTraitTest;
|
2021-04-24 16:39:56 -07:00
|
|
|
|
|
|
|
|
use Pterodactyl\Tests\TestCase;
|
|
|
|
|
use Pterodactyl\Traits\Commands\EnvironmentWriterTrait;
|
|
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
uses(TestCase::class);
|
|
|
|
|
dataset('variableDataProvider', function () {
|
|
|
|
|
return [['foo', 'foo'], ['abc123', 'abc123'], ['val"ue', '"val\"ue"'], ['my test value', '"my test value"'], ['mysql_p@assword', '"mysql_p@assword"'], ['mysql_p#assword', '"mysql_p#assword"'], ['mysql p@$$word', '"mysql p@$$word"'], ['mysql p%word', '"mysql p%word"'], ['mysql p#word', '"mysql p#word"'], ['abc_@#test', '"abc_@#test"'], ['test 123 $$$', '"test 123 $$$"'], ['#password%', '"#password%"'], ['$pass ', '"$pass "']];
|
|
|
|
|
});
|
|
|
|
|
test('variable is escaped properly', function ($input, $expected) {
|
|
|
|
|
$output = escapeEnvironmentValue($input);
|
|
|
|
|
expect($output)->toBe($expected);
|
|
|
|
|
})->with('variableDataProvider');
|
|
|
|
|
function escapeEnvironmentValue(string $value): string
|
2021-04-24 16:39:56 -07:00
|
|
|
{
|
2026-10-05 18:10:18 -04:00
|
|
|
$writer = new class
|
2021-04-24 16:39:56 -07:00
|
|
|
{
|
2026-10-05 18:10:18 -04:00
|
|
|
use EnvironmentWriterTrait;
|
|
|
|
|
};
|
2021-04-24 16:39:56 -07:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
return $writer->escapeEnvironmentValue($value);
|
2021-04-24 16:39:56 -07:00
|
|
|
}
|