Skip to content

Commit

Permalink
Merge branch '4.4' into 5.1
Browse files Browse the repository at this point in the history
* 4.4:
  fix merge
  Remove branch-version (keep them for contracts only)
  [HttpClient] relax auth bearer format requirements
  [PHPUnitBridge] Silence errors from mkdir()
  [DependencyInjection] Preload classes with union types correctly.
  [Serializer] fix decoding float XML attributes starting with 0
  add missing dutch translations
  Support PHPUnit 8 and PHPUnit 9 in constraint compatibility trait
  Add expectDeprecation, expectNotice, expectWarning, and expectError to TestCase polyfill
  Add missing exporter function for PHPUnit 7
  [Validator] Add missing romanian translations
  [Cache] Use correct expiry in ChainAdapter
  do not translate null placeholders or titles
  • Loading branch information
nicolas-grekas committed Oct 24, 2020
2 parents bc1db73 + 3ead7e2 commit 97a6a1f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
9 changes: 7 additions & 2 deletions HttpClientTrait.php
Expand Up @@ -111,8 +111,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.', get_debug_type($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, %s given.', \is_string($options['auth_bearer']) ? 'invalid string' : '"'.get_debug_type($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.', get_debug_type($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'])) {
Expand Down
4 changes: 2 additions & 2 deletions Tests/HttpClientTraitTest.php
Expand Up @@ -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, "stdClass" given.');
$this->expectExceptionMessage('Option "auth_bearer" must be a string, "stdClass" 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);
}

Expand Down
5 changes: 1 addition & 4 deletions composer.json
Expand Up @@ -46,8 +46,5 @@
"/Tests/"
]
},
"minimum-stability": "dev",
"extra": {
"branch-version": "5.1"
}
"minimum-stability": "dev"
}

0 comments on commit 97a6a1f

Please sign in to comment.