Skip to content

Commit af092fd

Browse files
committed
Merge branch '4.0'
* 4.0: (30 commits) [FrameworkBundle] fix tests [Serializer] Fixed throwing exception with option JSON_PARTIAL_OUTPUT_ON_ERROR [HttpKernel] Fix session handling: decouple "save" from setting response "private" swap filter/function and package names [HttpFoundation] Always call proxied handler::destroy() in StrictSessionHandler [HttpKernel] Fix compile error when a legacy container is fresh again Add tests for the HttpKernel request collector and redirection via cookies Uses cookies to track the requests redirection Tweaked some styles in the profiler tables Add type string to docblock for Process::setInput() [Security] Fail gracefully if the security token cannot be unserialized from the session [Form] AbstractLayoutTest - fix DOMDocument casing Run simple-phpunit with --no-suggest option [FrameworkBundle] Fix using "annotations.cached_reader" in after-removing passes bumped Symfony version to 4.0.4 updated VERSION for 4.0.3 updated CHANGELOG for 4.0.3 bumped Symfony version to 3.4.4 updated VERSION for 3.4.3 updated CHANGELOG for 3.4.3 ...
2 parents 933f269 + 5c50229 commit af092fd

File tree

6 files changed

+48
-10
lines changed

6 files changed

+48
-10
lines changed

Encoder/EncoderInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ interface EncoderInterface
2727
* @param string $format Format name
2828
* @param array $context Options that normalizers/encoders have access to
2929
*
30-
* @return scalar
30+
* @return string|int|float|bool
3131
*
3232
* @throws UnexpectedValueException
3333
*/

Encoder/JsonEncode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function encode($data, $format, array $context = array())
3838

3939
$encodedJson = json_encode($data, $context['json_encode_options']);
4040

41-
if (JSON_ERROR_NONE !== json_last_error()) {
41+
if (JSON_ERROR_NONE !== json_last_error() && (false === $encodedJson || !($context['json_encode_options'] & JSON_PARTIAL_OUTPUT_ON_ERROR))) {
4242
throw new NotEncodableValueException(json_last_error_msg());
4343
}
4444

Normalizer/DenormalizableInterface.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ interface DenormalizableInterface
2727
* It is important to understand that the denormalize() call should denormalize
2828
* recursively all child objects of the implementor.
2929
*
30-
* @param DenormalizerInterface $denormalizer The denormalizer is given so that you
31-
* can use it to denormalize objects contained within this object
32-
* @param array|scalar $data The data from which to re-create the object
33-
* @param string|null $format The format is optionally given to be able to denormalize differently
34-
* based on different input formats
35-
* @param array $context Options for denormalizing
30+
* @param DenormalizerInterface $denormalizer The denormalizer is given so that you
31+
* can use it to denormalize objects contained within this object
32+
* @param array|string|int|float|bool $data The data from which to re-create the object
33+
* @param string|null $format The format is optionally given to be able to denormalize
34+
* differently based on different input formats
35+
* @param array $context Options for denormalizing
3636
*
3737
* @return object
3838
*/

Normalizer/NormalizableInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ interface NormalizableInterface
3333
* based on different output formats
3434
* @param array $context Options for normalizing this object
3535
*
36-
* @return array|scalar
36+
* @return array|string|int|float|bool
3737
*/
3838
public function normalize(NormalizerInterface $normalizer, $format = null, array $context = array());
3939
}

Normalizer/NormalizerInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ interface NormalizerInterface
2929
* @param string $format Format the normalization result will be encoded as
3030
* @param array $context Context options for the normalizer
3131
*
32-
* @return array|scalar
32+
* @return array|string|int|float|bool
3333
*
3434
* @throws InvalidArgumentException Occurs when the object given is not an attempted type for the normalizer
3535
* @throws CircularReferenceException Occurs when the normalizer detects a circular reference when no circular

Tests/Encoder/JsonEncoderTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,44 @@ public function testOptions()
6565
$this->assertEquals($expected, $this->serializer->serialize($arr, 'json'), 'Context should not be persistent');
6666
}
6767

68+
/**
69+
* @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
70+
*/
71+
public function testEncodeNotUtf8WithoutPartialOnError()
72+
{
73+
$arr = array(
74+
'utf8' => 'Hello World!',
75+
'notUtf8' => "\xb0\xd0\xb5\xd0",
76+
);
77+
78+
$this->encoder->encode($arr, 'json');
79+
}
80+
81+
public function testEncodeNotUtf8WithPartialOnError()
82+
{
83+
$context = array('json_encode_options' => JSON_PARTIAL_OUTPUT_ON_ERROR);
84+
85+
$arr = array(
86+
'utf8' => 'Hello World!',
87+
'notUtf8' => "\xb0\xd0\xb5\xd0",
88+
);
89+
90+
$result = $this->encoder->encode($arr, 'json', $context);
91+
$jsonLastError = json_last_error();
92+
93+
$this->assertSame(JSON_ERROR_UTF8, $jsonLastError);
94+
$this->assertEquals('{"utf8":"Hello World!","notUtf8":null}', $result);
95+
96+
$this->assertEquals('0', $this->serializer->serialize(NAN, 'json', $context));
97+
}
98+
99+
public function testDecodeFalseString()
100+
{
101+
$result = $this->encoder->decode('false', 'json');
102+
$this->assertSame(JSON_ERROR_NONE, json_last_error());
103+
$this->assertFalse($result);
104+
}
105+
68106
protected function getJsonSource()
69107
{
70108
return '{"foo":"foo","bar":["a","b"],"baz":{"key":"val","key2":"val","A B":"bar","item":[{"title":"title1"},{"title":"title2"}],"Barry":{"FooBar":{"Baz":"Ed","@id":1}}},"qux":"1"}';

0 commit comments

Comments
 (0)