Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f7cdab3

Browse filesBrowse files
committed
dump non UTF-8 encoded strings as binary data
1 parent 243e59c commit f7cdab3
Copy full SHA for f7cdab3

File tree

3 files changed

+11
-13
lines changed
Filter options

3 files changed

+11
-13
lines changed

‎src/Symfony/Component/Yaml/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/CHANGELOG.md
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ CHANGELOG
44
3.1.0
55
-----
66

7+
* Strings that are not UTF-8 encoded will be dumped as base64 encoded binary
8+
data.
9+
710
* Added support for dumping multi line strings as literal blocks.
811

912
* Added support for parsing base64 encoded binary data when they are tagged
1013
with the `!!binary` tag.
1114

12-
* Added support for dumping binary data as base64 encoded strings by passing
13-
the `Yaml::DUMP_BASE64_BINARY_DATA` flag.
14-
1515
* Added support for parsing timestamps as `\DateTime` objects:
1616

1717
```php

‎src/Symfony/Component/Yaml/Inline.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Inline.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public static function dump($value, $flags = 0)
201201
return $repr;
202202
case '' == $value:
203203
return "''";
204-
case Yaml::DUMP_BASE64_BINARY_DATA & $flags && self::isBinaryString($value):
204+
case self::isBinaryString($value):
205205
return '!!binary '.base64_encode($value);
206206
case Escaper::requiresDoubleQuoting($value):
207207
return Escaper::escapeWithDoubleQuotes($value);
@@ -627,7 +627,7 @@ public static function evaluateBinaryScalar($scalar)
627627

628628
private static function isBinaryString($value)
629629
{
630-
return preg_match('/[^\x09-\x0d\x20-\xff]/', $value);
630+
return !preg_match('//u', $value);
631631
}
632632

633633
/**

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Tests/DumperTest.php
+6-8Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -277,14 +277,6 @@ public function getEscapeSequences()
277277
);
278278
}
279279

280-
public function testBinaryDataIsDumpedAsIsWithoutFlag()
281-
{
282-
$binaryData = file_get_contents(__DIR__.'/Fixtures/arrow.gif');
283-
$expected = "{ data: '".str_replace("'", "''", $binaryData)."' }";
284-
285-
$this->assertSame($expected, $this->dumper->dump(array('data' => $binaryData)));
286-
}
287-
288280
public function testBinaryDataIsDumpedBase64EncodedWithFlag()
289281
{
290282
$binaryData = file_get_contents(__DIR__.'/Fixtures/arrow.gif');
@@ -293,6 +285,12 @@ public function testBinaryDataIsDumpedBase64EncodedWithFlag()
293285
$this->assertSame($expected, $this->dumper->dump(array('data' => $binaryData), 0, 0, Yaml::DUMP_BASE64_BINARY_DATA));
294286
}
295287

288+
public function testDumpingNonUtf8DataTriggersException()
289+
{
290+
// "für" (ISO-8859-1 encoded)
291+
$this->assertSame('!!binary ZsM/cg==', $this->dumper->dump("f\xc3\x3fr"));
292+
}
293+
296294
/**
297295
* @dataProvider objectAsMapProvider
298296
*/

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.