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 0bba6ad

Browse filesBrowse files
Fix exception thrown by YamlEncoder
1 parent 322e13c commit 0bba6ad
Copy full SHA for 0bba6ad

File tree

2 files changed

+16
-1
lines changed
Filter options

2 files changed

+16
-1
lines changed

‎src/Symfony/Component/Serializer/Encoder/YamlEncoder.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Encoder/YamlEncoder.php
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111

1212
namespace Symfony\Component\Serializer\Encoder;
1313

14+
use Symfony\Component\Serializer\Exception\NotEncodableValueException;
1415
use Symfony\Component\Serializer\Exception\RuntimeException;
1516
use Symfony\Component\Yaml\Dumper;
17+
use Symfony\Component\Yaml\Exception\ParseException;
1618
use Symfony\Component\Yaml\Parser;
1719
use Symfony\Component\Yaml\Yaml;
1820

@@ -85,7 +87,11 @@ public function decode(string $data, string $format, array $context = []): mixed
8587
{
8688
$context = array_merge($this->defaultContext, $context);
8789

88-
return $this->parser->parse($data, $context[self::YAML_FLAGS]);
90+
try {
91+
return $this->parser->parse($data, $context[self::YAML_FLAGS]);
92+
} catch (ParseException $e) {
93+
throw new NotEncodableValueException($e->getMessage(), $e->getCode(), $e);
94+
}
8995
}
9096

9197
public function supportsDecoding(string $format): bool

‎src/Symfony/Component/Serializer/Tests/Encoder/YamlEncoderTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Tests/Encoder/YamlEncoderTest.php
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Serializer\Encoder\YamlEncoder;
16+
use Symfony\Component\Serializer\Exception\NotEncodableValueException;
1617
use Symfony\Component\Yaml\Yaml;
1718

1819
/**
@@ -81,4 +82,12 @@ public function testContext()
8182
$this->assertEquals(['foo' => $obj], $encoder->decode("foo: !php/object 'O:8:\"stdClass\":1:{s:3:\"bar\";i:2;}'", 'yaml'));
8283
$this->assertEquals(['foo' => null], $encoder->decode("foo: !php/object 'O:8:\"stdClass\":1:{s:3:\"bar\";i:2;}'", 'yaml', [YamlEncoder::YAML_FLAGS => 0]));
8384
}
85+
86+
public function testInvalidYaml()
87+
{
88+
$encoder = new YamlEncoder();
89+
90+
$this->expectException(NotEncodableValueException::class);
91+
$encoder->decode("\t", 'yaml');
92+
}
8493
}

0 commit comments

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