Merge branch '4.3' into 4.4

* 4.3:
  [Config] Disable default alphabet sorting in glob function due of unstable sort
  [HttpClient] always return the empty string when the response cannot have a body
  [TwigBundle][exception] Added missing css variable to highlight line in trace
  [Serializer] Improve messages for unexpected resources values
  [SecurityBundle] correct types for default arguments for firewall configs
This commit is contained in:
Nicolas Grekas 2019-10-30 13:55:29 +01:00
commit 0b5b6fa79f
14 changed files with 51 additions and 49 deletions

2
link
View File

@ -66,6 +66,6 @@ foreach (glob("$pathToProject/vendor/symfony/*", GLOB_ONLYDIR | GLOB_NOSORT) as
echo "\"$package\" has been linked to \"$sfPackages[$package]\".".PHP_EOL;
}
foreach (glob("$pathToProject/var/cache/*") as $cacheDir) {
foreach (glob("$pathToProject/var/cache/*", GLOB_NOSORT) as $cacheDir) {
$filesystem->remove($cacheDir);
}

View File

@ -165,15 +165,15 @@
<argument /> <!-- name -->
<argument /> <!-- user_checker -->
<argument /> <!-- request_matcher -->
<argument /> <!-- security enabled -->
<argument /> <!-- stateless -->
<argument>false</argument> <!-- security enabled -->
<argument>false</argument> <!-- stateless -->
<argument /> <!-- provider -->
<argument /> <!-- context -->
<argument /> <!-- entry_point -->
<argument /> <!-- access_denied_handler -->
<argument /> <!-- access_denied_url -->
<argument type="collection" /> <!-- listeners -->
<argument /> <!-- switch_user -->
<argument>null</argument> <!-- switch_user -->
</service>
<service id="security.logout_url_generator" class="Symfony\Component\Security\Http\Logout\LogoutUrlGenerator">

View File

@ -29,6 +29,7 @@
--shadow: 0px 0px 1px rgba(128, 128, 128, .2);
--border: 1px solid #e0e0e0;
--background-error: var(--color-error);
--trace-selected-background: #F7E5A1;
--highlight-comment: #969896;
--highlight-default: #222222;
--highlight-keyword: #a71d5d;

View File

@ -102,7 +102,9 @@ class GlobResource implements \IteratorAggregate, SelfCheckingResourceInterface
$prefix = str_replace('\\', '/', $this->prefix);
if (0 !== strpos($this->prefix, 'phar://') && false === strpos($this->pattern, '/**/') && (\defined('GLOB_BRACE') || false === strpos($this->pattern, '{'))) {
foreach (glob($this->prefix.$this->pattern, \defined('GLOB_BRACE') ? GLOB_BRACE : 0) as $path) {
$paths = glob($this->prefix.$this->pattern, GLOB_NOSORT | (\defined('GLOB_BRACE') ? GLOB_BRACE : 0));
sort($paths);
foreach ($paths as $path) {
if ($this->excludedPrefixes) {
$normalizedPath = str_replace('\\', '/', $path);
do {

View File

@ -595,7 +595,8 @@ class Finder implements \IteratorAggregate, \Countable
foreach ((array) $dirs as $dir) {
if (is_dir($dir)) {
$resolvedDirs[] = $this->normalizeDir($dir);
} elseif ($glob = glob($dir, (\defined('GLOB_BRACE') ? GLOB_BRACE : 0) | GLOB_ONLYDIR)) {
} elseif ($glob = glob($dir, (\defined('GLOB_BRACE') ? GLOB_BRACE : 0) | GLOB_ONLYDIR | GLOB_NOSORT)) {
sort($glob);
$resolvedDirs = array_merge($resolvedDirs, array_map([$this, 'normalizeDir'], $glob));
} else {
throw new DirectoryNotFoundException(sprintf('The "%s" directory does not exist.', $dir));

View File

@ -117,11 +117,15 @@ trait ResponseTrait
}
}
if (null === $content) {
throw new TransportException('Cannot get the content of the response twice: buffering is disabled.');
if (null !== $content) {
return $content;
}
return $content;
if ('HEAD' === $this->info['http_method'] || \in_array($this->info['http_code'], [204, 304], true)) {
return '';
}
throw new TransportException('Cannot get the content of the response twice: buffering is disabled.');
}
foreach (self::stream([$this]) as $chunk) {

View File

@ -75,34 +75,4 @@ abstract class HttpClientTestCase extends BaseHttpClientTestCase
$response = $client->request('GET', 'http://localhost:8057/404');
$stream = $response->toStream();
}
public function testInfoOnCanceledResponse()
{
$this->markTestSkipped('Implemented as of version 4.4');
}
public function testBufferSink()
{
$this->markTestSkipped('Implemented as of version 4.4');
}
public function testConditionalBuffering()
{
$this->markTestSkipped('Implemented as of version 4.4');
}
public function testReentrantBufferCallback()
{
$this->markTestSkipped('Implemented as of version 4.4');
}
public function testThrowingBufferCallback()
{
$this->markTestSkipped('Implemented as of version 4.4');
}
public function testMaxDuration()
{
$this->markTestSkipped('Implemented as of version 4.4');
}
}

View File

@ -468,7 +468,7 @@ class XmlEncoder implements EncoderInterface, DecoderInterface, NormalizationAwa
return $this->appendNode($parentNode, $data, 'data');
}
throw new NotEncodableValueException(sprintf('An unexpected value could not be serialized: %s', var_export($data, true)));
throw new NotEncodableValueException(sprintf('An unexpected value could not be serialized: %s', !\is_resource($data) ? var_export($data, true) : sprintf('%s resource', get_resource_type($data))));
}
/**

View File

@ -173,7 +173,7 @@ class Serializer implements SerializerInterface, ContextAwareNormalizerInterface
throw new NotNormalizableValueException(sprintf('Could not normalize object of type %s, no supporting normalizer found.', \get_class($data)));
}
throw new NotNormalizableValueException(sprintf('An unexpected value could not be normalized: %s', var_export($data, true)));
throw new NotNormalizableValueException(sprintf('An unexpected value could not be normalized: %s', !\is_resource($data) ? var_export($data, true) : sprintf('%s resource', get_resource_type($data))));
}
/**

View File

@ -14,6 +14,7 @@ namespace Symfony\Component\Serializer\Tests\Encoder;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Serializer\Encoder\XmlEncoder;
use Symfony\Component\Serializer\Exception\NotEncodableValueException;
use Symfony\Component\Serializer\Normalizer\CustomNormalizer;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Component\Serializer\Serializer;
@ -816,6 +817,14 @@ XML;
$this->assertEquals($this->createXmlWithDateTimeField(), $actualXml);
}
public function testNotEncodableValueExceptionMessageForAResource()
{
$this->expectException(NotEncodableValueException::class);
$this->expectExceptionMessage('An unexpected value could not be serialized: stream resource');
(new XmlEncoder())->encode(tmpfile(), 'xml');
}
public function testEncodeComment()
{
$expected = <<<'XML'

View File

@ -17,6 +17,7 @@ use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
use Symfony\Component\Serializer\Exception\NotNormalizableValueException;
use Symfony\Component\Serializer\Mapping\ClassDiscriminatorFromClassMetadata;
use Symfony\Component\Serializer\Mapping\ClassDiscriminatorMapping;
use Symfony\Component\Serializer\Mapping\ClassMetadata;
@ -481,6 +482,14 @@ class SerializerTest extends TestCase
$this->serializerWithClassDiscriminator()->deserialize('{"one":1}', DummyMessageInterface::class, 'json');
}
public function testNotNormalizableValueExceptionMessageForAResource()
{
$this->expectException(NotNormalizableValueException::class);
$this->expectExceptionMessage('An unexpected value could not be normalized: stream resource');
(new Serializer())->normalize(tmpfile());
}
private function serializerWithClassDiscriminator()
{
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));

View File

@ -89,7 +89,8 @@ function findTranslationFiles($originalFilePath, $localeToAnalyze)
$originalFileName = basename($originalFilePath);
$translationFileNamePattern = str_replace('.en.', '.*.', $originalFileName);
$translationFiles = glob($translationsDir.'/'.$translationFileNamePattern);
$translationFiles = glob($translationsDir.'/'.$translationFileNamePattern, GLOB_NOSORT);
sort($translationFiles);
foreach ($translationFiles as $filePath) {
$locale = extractLocaleFromFilePath($filePath);

View File

@ -29,15 +29,20 @@ foreach ($_SERVER as $k => $v) {
}
}
$json = json_encode($vars, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
switch ($vars['REQUEST_URI']) {
default:
exit;
case '/head':
header('Content-Length: '.strlen($json), true);
break;
case '/':
case '/?a=a&b=b':
case 'http://127.0.0.1:8057/':
case 'http://localhost:8057/':
header('Content-Type: application/json');
ob_start('ob_gzhandler');
break;
@ -85,6 +90,7 @@ switch ($vars['REQUEST_URI']) {
case '/304':
header('Content-Length: 10', true, 304);
echo '12345';
return;
case '/307':
@ -153,4 +159,4 @@ switch ($vars['REQUEST_URI']) {
header('Content-Type: application/json', true);
echo json_encode($vars, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
echo $json;

View File

@ -75,26 +75,24 @@ abstract class HttpClientTestCase extends TestCase
public function testHeadRequest()
{
$client = $this->getHttpClient(__FUNCTION__);
$response = $client->request('HEAD', 'http://localhost:8057', [
$response = $client->request('HEAD', 'http://localhost:8057/head', [
'headers' => ['Foo' => 'baR'],
'user_data' => $data = new \stdClass(),
'buffer' => false,
]);
$this->assertSame([], $response->getInfo('response_headers'));
$this->assertSame($data, $response->getInfo()['user_data']);
$this->assertSame(200, $response->getStatusCode());
$info = $response->getInfo();
$this->assertNull($info['error']);
$this->assertSame(0, $info['redirect_count']);
$this->assertSame('HTTP/1.1 200 OK', $info['response_headers'][0]);
$this->assertSame('Host: localhost:8057', $info['response_headers'][1]);
$this->assertSame('http://localhost:8057/', $info['url']);
$headers = $response->getHeaders();
$this->assertSame('localhost:8057', $headers['host'][0]);
$this->assertSame(['application/json'], $headers['content-type']);
$this->assertTrue(0 < $headers['content-length'][0]);
$this->assertSame('', $response->getContent());
}
@ -329,6 +327,7 @@ abstract class HttpClientTestCase extends TestCase
$client = $this->getHttpClient(__FUNCTION__);
$response = $client->request('GET', 'http://localhost:8057/304', [
'headers' => ['If-Match' => '"abc"'],
'buffer' => false,
]);
$this->assertSame(304, $response->getStatusCode());