Skip to content

Commit a3950ea

Browse files
committed
[Yaml] Add the Yaml::DUMP_FORCE_DOUBLE_QUOTES_ON_VALUES flag to enforce double quotes around string values
1 parent 2192ef6 commit a3950ea

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

src/Symfony/Component/Yaml/CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ CHANGELOG
55
---
66

77
* Add compact nested mapping support by using the `Yaml::DUMP_COMPACT_NESTED_MAPPING` flag
8-
* Add force dumping with quotes support by using the `Yaml::DUMP_FORCE_QUOTES` flag
8+
* Add the `Yaml::DUMP_FORCE_DOUBLE_QUOTES_ON_VALUES` flag to enforce double quotes around string values
99

1010
7.2
1111
---

src/Symfony/Component/Yaml/Inline.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public static function dump(mixed $value, int $flags = 0, bool $rootLevel = fals
173173
case self::isBinaryString($value):
174174
return '!!binary '.base64_encode($value);
175175
case Escaper::requiresDoubleQuoting($value):
176-
case Yaml::DUMP_FORCE_QUOTES & $flags:
176+
case Yaml::DUMP_FORCE_DOUBLE_QUOTES_ON_VALUES & $flags:
177177
return Escaper::escapeWithDoubleQuotes($value);
178178
case Escaper::requiresSingleQuoting($value):
179179
$singleQuoted = Escaper::escapeWithSingleQuotes($value);
@@ -243,7 +243,7 @@ private static function dumpArray(array $value, int $flags): string
243243
private static function dumpHashArray(array|\ArrayObject|\stdClass $value, int $flags): string
244244
{
245245
$output = [];
246-
$keyFlags = $flags &~ Yaml::DUMP_FORCE_QUOTES;
246+
$keyFlags = $flags &~ Yaml::DUMP_FORCE_DOUBLE_QUOTES_ON_VALUES;
247247
foreach ($value as $key => $val) {
248248
if (\is_int($key) && Yaml::DUMP_NUMERIC_KEY_AS_STRING & $flags) {
249249
$key = (string) $key;

src/Symfony/Component/Yaml/Tests/DumperTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -910,9 +910,9 @@ public function testDumpNullAsTilde()
910910
$this->assertSame('{ foo: ~ }', $this->dumper->dump(['foo' => null], 0, 0, Yaml::DUMP_NULL_AS_TILDE));
911911
}
912912

913-
public function testForceQuotes()
913+
public function testCanForceQuotesOnValues()
914914
{
915-
$this->assertSame('{ foo: "bat", bar: 23 }', $this->dumper->dump(['foo' => 'bat', 'bar' => 23], 0, 0, Yaml::DUMP_FORCE_QUOTES));
915+
$this->assertSame('{ foo: "bat", bar: 23 }', $this->dumper->dump(['foo' => 'bat', 'bar' => 23], 0, 0, Yaml::DUMP_FORCE_DOUBLE_QUOTES_ON_VALUES));
916916
}
917917

918918
/**

src/Symfony/Component/Yaml/Yaml.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Yaml
3737
public const DUMP_NUMERIC_KEY_AS_STRING = 4096;
3838
public const DUMP_NULL_AS_EMPTY = 8192;
3939
public const DUMP_COMPACT_NESTED_MAPPING = 16384;
40-
public const DUMP_FORCE_QUOTES = 32768;
40+
public const DUMP_FORCE_DOUBLE_QUOTES_ON_VALUES = 32768;
4141

4242
/**
4343
* Parses a YAML file into a PHP value.

0 commit comments

Comments
 (0)