Content-Length: 2755 | pFad | http://github.com/symfony/symfony/pull/59323.patch
thub.com
From ab9de2d10f32646d94ccf850edd143928363a469 Mon Sep 17 00:00:00 2001
From: Vincent Langlet
Date: Sun, 29 Dec 2024 22:22:56 +0100
Subject: [PATCH] Fix exception thrown by YamlEncoder
---
src/Symfony/Component/Serializer/Encoder/YamlEncoder.php | 8 +++++++-
.../Serializer/Tests/Encoder/YamlEncoderTest.php | 9 +++++++++
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/src/Symfony/Component/Serializer/Encoder/YamlEncoder.php b/src/Symfony/Component/Serializer/Encoder/YamlEncoder.php
index 223cd79333f6a..1013129db8dfd 100644
--- a/src/Symfony/Component/Serializer/Encoder/YamlEncoder.php
+++ b/src/Symfony/Component/Serializer/Encoder/YamlEncoder.php
@@ -11,8 +11,10 @@
namespace Symfony\Component\Serializer\Encoder;
+use Symfony\Component\Serializer\Exception\NotEncodableValueException;
use Symfony\Component\Serializer\Exception\RuntimeException;
use Symfony\Component\Yaml\Dumper;
+use Symfony\Component\Yaml\Exception\ParseException;
use Symfony\Component\Yaml\Parser;
use Symfony\Component\Yaml\Yaml;
@@ -85,7 +87,11 @@ public function decode(string $data, string $format, array $context = []): mixed
{
$context = array_merge($this->defaultContext, $context);
- return $this->parser->parse($data, $context[self::YAML_FLAGS]);
+ try {
+ return $this->parser->parse($data, $context[self::YAML_FLAGS]);
+ } catch (ParseException $e) {
+ throw new NotEncodableValueException($e->getMessage(), $e->getCode(), $e);
+ }
}
public function supportsDecoding(string $format): bool
diff --git a/src/Symfony/Component/Serializer/Tests/Encoder/YamlEncoderTest.php b/src/Symfony/Component/Serializer/Tests/Encoder/YamlEncoderTest.php
index 33ee49f5d6b45..f647fe4233c78 100644
--- a/src/Symfony/Component/Serializer/Tests/Encoder/YamlEncoderTest.php
+++ b/src/Symfony/Component/Serializer/Tests/Encoder/YamlEncoderTest.php
@@ -13,6 +13,7 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\Serializer\Encoder\YamlEncoder;
+use Symfony\Component\Serializer\Exception\NotEncodableValueException;
use Symfony\Component\Yaml\Yaml;
/**
@@ -81,4 +82,12 @@ public function testContext()
$this->assertEquals(['foo' => $obj], $encoder->decode("foo: !php/object 'O:8:\"stdClass\":1:{s:3:\"bar\";i:2;}'", 'yaml'));
$this->assertEquals(['foo' => null], $encoder->decode("foo: !php/object 'O:8:\"stdClass\":1:{s:3:\"bar\";i:2;}'", 'yaml', [YamlEncoder::YAML_FLAGS => 0]));
}
+
+ public function testInvalidYaml()
+ {
+ $encoder = new YamlEncoder();
+
+ $this->expectException(NotEncodableValueException::class);
+ $encoder->decode("\t", 'yaml');
+ }
}
--- a PPN by Garber Painting Akron. With Image Size Reduction included!Fetched URL: http://github.com/symfony/symfony/pull/59323.patch
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy