diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php index 53cb189105..4cf1dc028b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php @@ -185,6 +185,7 @@ class JsonDescriptor extends Descriptor private function writeData(array $data, array $options) { $flags = isset($options['json_encoding']) ? $options['json_encoding'] : 0; + $this->write(json_encode($data, $flags | JSON_PRETTY_PRINT)."\n"); } diff --git a/src/Symfony/Component/Console/Descriptor/JsonDescriptor.php b/src/Symfony/Component/Console/Descriptor/JsonDescriptor.php index 197b843d4b..f5a143800b 100644 --- a/src/Symfony/Component/Console/Descriptor/JsonDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/JsonDescriptor.php @@ -97,7 +97,9 @@ class JsonDescriptor extends Descriptor */ private function writeData(array $data, array $options) { - $this->write(json_encode($data, isset($options['json_encoding']) ? $options['json_encoding'] : 0)); + $flags = isset($options['json_encoding']) ? $options['json_encoding'] : 0; + + $this->write(json_encode($data, $flags)); } /** diff --git a/src/Symfony/Component/Form/Console/Descriptor/JsonDescriptor.php b/src/Symfony/Component/Form/Console/Descriptor/JsonDescriptor.php index 18a288b444..9c4c68a5cc 100644 --- a/src/Symfony/Component/Form/Console/Descriptor/JsonDescriptor.php +++ b/src/Symfony/Component/Form/Console/Descriptor/JsonDescriptor.php @@ -94,7 +94,8 @@ class JsonDescriptor extends Descriptor private function writeData(array $data, array $options) { - $flags = $options['json_encoding'] ?? 0; + $flags = isset($options['json_encoding']) ? $options['json_encoding'] : 0; + $this->output->write(json_encode($data, $flags | JSON_PRETTY_PRINT)."\n"); } diff --git a/src/Symfony/Component/HttpFoundation/JsonResponse.php b/src/Symfony/Component/HttpFoundation/JsonResponse.php index 817cbb9afc..4dae091faa 100644 --- a/src/Symfony/Component/HttpFoundation/JsonResponse.php +++ b/src/Symfony/Component/HttpFoundation/JsonResponse.php @@ -148,6 +148,10 @@ class JsonResponse extends Response throw $e; } + if (\PHP_VERSION_ID >= 70300 && (JSON_THROW_ON_ERROR & $this->encodingOptions)) { + return $this->setJson($data); + } + if (JSON_ERROR_NONE !== json_last_error()) { throw new \InvalidArgumentException(json_last_error_msg()); } diff --git a/src/Symfony/Component/Security/Http/Firewall/X509AuthenticationListener.php b/src/Symfony/Component/Security/Http/Firewall/X509AuthenticationListener.php index 2d3c26f28c..1958354702 100644 --- a/src/Symfony/Component/Security/Http/Firewall/X509AuthenticationListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/X509AuthenticationListener.php @@ -44,7 +44,10 @@ class X509AuthenticationListener extends AbstractPreAuthenticatedListener $user = null; if ($request->server->has($this->userKey)) { $user = $request->server->get($this->userKey); - } elseif ($request->server->has($this->credentialKey) && preg_match('#/emailAddress=(.+\@.+\..+)(/|$)#', $request->server->get($this->credentialKey), $matches)) { + } elseif ( + $request->server->has($this->credentialKey) + && preg_match('#emailAddress=(.+\@.+\.[^,/]+)($|,|/)#', $request->server->get($this->credentialKey), $matches) + ) { $user = $matches[1]; } diff --git a/src/Symfony/Component/Security/Http/Tests/Firewall/X509AuthenticationListenerTest.php b/src/Symfony/Component/Security/Http/Tests/Firewall/X509AuthenticationListenerTest.php index c55eaae0f3..577ca7c38f 100644 --- a/src/Symfony/Component/Security/Http/Tests/Firewall/X509AuthenticationListenerTest.php +++ b/src/Symfony/Component/Security/Http/Tests/Firewall/X509AuthenticationListenerTest.php @@ -56,9 +56,8 @@ class X509AuthenticationListenerTest extends TestCase /** * @dataProvider dataProviderGetPreAuthenticatedDataNoUser */ - public function testGetPreAuthenticatedDataNoUser($emailAddress) + public function testGetPreAuthenticatedDataNoUser($emailAddress, $credentials) { - $credentials = 'CN=Sample certificate DN/emailAddress='.$emailAddress; $request = new Request([], [], [], [], [], ['SSL_CLIENT_S_DN' => $credentials]); $tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock(); @@ -76,10 +75,12 @@ class X509AuthenticationListenerTest extends TestCase public static function dataProviderGetPreAuthenticatedDataNoUser() { - return [ - 'basicEmailAddress' => ['cert@example.com'], - 'emailAddressWithPlusSign' => ['cert+something@example.com'], - ]; + yield ['cert@example.com', 'CN=Sample certificate DN/emailAddress=cert@example.com']; + yield ['cert+something@example.com', 'CN=Sample certificate DN/emailAddress=cert+something@example.com']; + yield ['cert@example.com', 'CN=Sample certificate DN,emailAddress=cert@example.com']; + yield ['cert+something@example.com', 'CN=Sample certificate DN,emailAddress=cert+something@example.com']; + yield ['cert+something@example.com', 'emailAddress=cert+something@example.com,CN=Sample certificate DN']; + yield ['cert+something@example.com', 'emailAddress=cert+something@example.com']; } /** diff --git a/src/Symfony/Component/Serializer/Encoder/JsonDecode.php b/src/Symfony/Component/Serializer/Encoder/JsonDecode.php index 789e166b50..ceedce69ee 100644 --- a/src/Symfony/Component/Serializer/Encoder/JsonDecode.php +++ b/src/Symfony/Component/Serializer/Encoder/JsonDecode.php @@ -92,7 +92,15 @@ class JsonDecode implements DecoderInterface $recursionDepth = $context[self::RECURSION_DEPTH] ?? $this->defaultContext[self::RECURSION_DEPTH]; $options = $context[self::OPTIONS] ?? $this->defaultContext[self::OPTIONS]; - $decodedData = json_decode($data, $associative, $recursionDepth, $options); + try { + $decodedData = json_decode($data, $associative, $recursionDepth, $options); + } catch (\JsonException $e) { + throw new NotEncodableValueException($e->getMessage(), 0, $e); + } + + if (\PHP_VERSION_ID >= 70300 && (JSON_THROW_ON_ERROR & $options)) { + return $decodedData; + } if (JSON_ERROR_NONE !== json_last_error()) { throw new NotEncodableValueException(json_last_error_msg()); diff --git a/src/Symfony/Component/Serializer/Encoder/JsonEncode.php b/src/Symfony/Component/Serializer/Encoder/JsonEncode.php index ca9fc9e5d7..681e3c4941 100644 --- a/src/Symfony/Component/Serializer/Encoder/JsonEncode.php +++ b/src/Symfony/Component/Serializer/Encoder/JsonEncode.php @@ -50,6 +50,10 @@ class JsonEncode implements EncoderInterface $jsonEncodeOptions = $context[self::OPTIONS] ?? $this->defaultContext[self::OPTIONS]; $encodedJson = json_encode($data, $jsonEncodeOptions); + if (\PHP_VERSION_ID >= 70300 && (JSON_THROW_ON_ERROR & $jsonEncodeOptions)) { + return $encodedJson; + } + if (JSON_ERROR_NONE !== json_last_error() && (false === $encodedJson || !($jsonEncodeOptions & JSON_PARTIAL_OUTPUT_ON_ERROR))) { throw new NotEncodableValueException(json_last_error_msg()); }