From 85b2573d87d9bda42939f5d73bfc3beee5ed2828 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Tue, 20 Oct 2020 15:00:49 +0200 Subject: [PATCH 1/2] [HttpClient] relax auth bearer format requirements --- HttpClientTrait.php | 9 +++++++-- Tests/HttpClientTraitTest.php | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/HttpClientTrait.php b/HttpClientTrait.php index 2631830..2431e80 100644 --- a/HttpClientTrait.php +++ b/HttpClientTrait.php @@ -110,8 +110,13 @@ private static function prepareRequest(?string $method, ?string $url, array $opt throw new InvalidArgumentException(sprintf('Option "auth_basic" must be string or an array, "%s" given.', \gettype($options['auth_basic']))); } - if (isset($options['auth_bearer']) && (!\is_string($options['auth_bearer']) || !preg_match('{^[-._=:~+/0-9a-zA-Z]++$}', $options['auth_bearer']))) { - throw new InvalidArgumentException(sprintf('Option "auth_bearer" must be a string containing only characters from the base 64 alphabet, '.(\is_string($options['auth_bearer']) ? 'invalid string given.' : '"%s" given.'), \gettype($options['auth_bearer']))); + if (isset($options['auth_bearer'])) { + if (!\is_string($options['auth_bearer'])) { + throw new InvalidArgumentException(sprintf('Option "auth_bearer" must be a string, "%s" given.', \gettype($options['auth_bearer']))); + } + if (preg_match('{[^\x21-\x7E]}', $options['auth_bearer'])) { + throw new InvalidArgumentException('Invalid character found in option "auth_bearer": '.json_encode($options['auth_bearer']).'.'); + } } if (isset($options['auth_basic'], $options['auth_bearer'])) { diff --git a/Tests/HttpClientTraitTest.php b/Tests/HttpClientTraitTest.php index 477c33d..bce71ce 100644 --- a/Tests/HttpClientTraitTest.php +++ b/Tests/HttpClientTraitTest.php @@ -179,14 +179,14 @@ public function testAuthBearerOption() public function testInvalidAuthBearerOption() { $this->expectException('Symfony\Component\HttpClient\Exception\InvalidArgumentException'); - $this->expectExceptionMessage('Option "auth_bearer" must be a string containing only characters from the base 64 alphabet, "object" given.'); + $this->expectExceptionMessage('Option "auth_bearer" must be a string, "object" given.'); self::prepareRequest('POST', 'http://example.com', ['auth_bearer' => new \stdClass()], HttpClientInterface::OPTIONS_DEFAULTS); } public function testInvalidAuthBearerValue() { $this->expectException('Symfony\Component\HttpClient\Exception\InvalidArgumentException'); - $this->expectExceptionMessage('Option "auth_bearer" must be a string containing only characters from the base 64 alphabet, invalid string given.'); + $this->expectExceptionMessage('Invalid character found in option "auth_bearer": "a\nb".'); self::prepareRequest('POST', 'http://example.com', ['auth_bearer' => "a\nb"], HttpClientInterface::OPTIONS_DEFAULTS); } From 3ead7e297f4cc8a84661ef1f411c029acb34bc11 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sat, 24 Oct 2020 13:50:19 +0200 Subject: [PATCH 2/2] Merge branch '3.4' into 4.4 * 3.4: Remove branch-version (keep them for contracts only) [Serializer] fix decoding float XML attributes starting with 0 add missing dutch translations [Validator] Add missing romanian translations do not translate null placeholders or titles --- composer.json | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 8d0d3d6..843fe8e 100644 --- a/composer.json +++ b/composer.json @@ -42,8 +42,5 @@ "/Tests/" ] }, - "minimum-stability": "dev", - "extra": { - "branch-version": "4.4" - } + "minimum-stability": "dev" }