From 6b7044fc0112b49a866ff94debc866384fe90ba0 Mon Sep 17 00:00:00 2001 From: Douglas Greenshields Date: Wed, 23 Oct 2019 10:40:35 +0100 Subject: [PATCH 1/5] [SecurityBundle] correct types for default arguments for firewall configs --- .../Bundle/SecurityBundle/Resources/config/security.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bundle/SecurityBundle/Resources/config/security.xml b/src/Symfony/Bundle/SecurityBundle/Resources/config/security.xml index 4a2b936c71..98b7f3bee0 100644 --- a/src/Symfony/Bundle/SecurityBundle/Resources/config/security.xml +++ b/src/Symfony/Bundle/SecurityBundle/Resources/config/security.xml @@ -150,15 +150,15 @@ - - + false + false - + null From ad2ce276c7f276f391fc1ec095bc9dbc0ef47eb3 Mon Sep 17 00:00:00 2001 From: Thomas Calvet Date: Sun, 27 Oct 2019 17:07:41 +0100 Subject: [PATCH 2/5] [Serializer] Improve messages for unexpected resources values --- src/Symfony/Component/Serializer/Encoder/XmlEncoder.php | 2 +- src/Symfony/Component/Serializer/Serializer.php | 2 +- .../Serializer/Tests/Encoder/XmlEncoderTest.php | 9 +++++++++ .../Component/Serializer/Tests/SerializerTest.php | 9 +++++++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php b/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php index 3a76665a0b..c1e1109130 100644 --- a/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php +++ b/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php @@ -426,7 +426,7 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec 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)))); } /** diff --git a/src/Symfony/Component/Serializer/Serializer.php b/src/Symfony/Component/Serializer/Serializer.php index fd6b7dd059..a29a1482dd 100644 --- a/src/Symfony/Component/Serializer/Serializer.php +++ b/src/Symfony/Component/Serializer/Serializer.php @@ -164,7 +164,7 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz 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)))); } /** diff --git a/src/Symfony/Component/Serializer/Tests/Encoder/XmlEncoderTest.php b/src/Symfony/Component/Serializer/Tests/Encoder/XmlEncoderTest.php index 4f83bf3a58..f1a8b6ab48 100644 --- a/src/Symfony/Component/Serializer/Tests/Encoder/XmlEncoderTest.php +++ b/src/Symfony/Component/Serializer/Tests/Encoder/XmlEncoderTest.php @@ -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; @@ -679,6 +680,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'); + } + /** * @return XmlEncoder */ diff --git a/src/Symfony/Component/Serializer/Tests/SerializerTest.php b/src/Symfony/Component/Serializer/Tests/SerializerTest.php index c4814e364f..5652768fca 100644 --- a/src/Symfony/Component/Serializer/Tests/SerializerTest.php +++ b/src/Symfony/Component/Serializer/Tests/SerializerTest.php @@ -13,6 +13,7 @@ namespace Symfony\Component\Serializer\Tests; use PHPUnit\Framework\TestCase; use Symfony\Component\Serializer\Encoder\JsonEncoder; +use Symfony\Component\Serializer\Exception\NotNormalizableValueException; use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer; use Symfony\Component\Serializer\Normalizer\CustomNormalizer; use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface; @@ -328,6 +329,14 @@ class SerializerTest extends TestCase $this->assertEquals(new Foo(new Bar('baz')), $serializer->deserialize($jsonData, Foo::class, 'json')); } + + public function testNotNormalizableValueExceptionMessageForAResource() + { + $this->expectException(NotNormalizableValueException::class); + $this->expectExceptionMessage('An unexpected value could not be normalized: stream resource'); + + (new Serializer())->normalize(tmpfile()); + } } class Model From 5f19501fc4d5b564d2e3ee8a5a1be83252893d2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Tue, 29 Oct 2019 15:56:06 +0100 Subject: [PATCH 3/5] [TwigBundle][exception] Added missing css variable to highlight line in trace --- src/Symfony/Bundle/TwigBundle/Resources/views/exception.css.twig | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Symfony/Bundle/TwigBundle/Resources/views/exception.css.twig b/src/Symfony/Bundle/TwigBundle/Resources/views/exception.css.twig index 8c1f9af2a0..b7eb560002 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/views/exception.css.twig +++ b/src/Symfony/Bundle/TwigBundle/Resources/views/exception.css.twig @@ -28,6 +28,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; From f78e14332e152b0bad504a9e20987bfc52f31e7a Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 30 Oct 2019 12:53:18 +0100 Subject: [PATCH 4/5] [HttpClient] always return the empty string when the response cannot have a body --- .../Component/HttpClient/Response/ResponseTrait.php | 10 +++++++--- .../Component/HttpClient/Tests/MockHttpClientTest.php | 2 +- .../Contracts/HttpClient/Test/Fixtures/web/index.php | 10 ++++++++-- .../Contracts/HttpClient/Test/HttpClientTestCase.php | 9 ++++----- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/Symfony/Component/HttpClient/Response/ResponseTrait.php b/src/Symfony/Component/HttpClient/Response/ResponseTrait.php index 8a1d9a9077..5179a07418 100644 --- a/src/Symfony/Component/HttpClient/Response/ResponseTrait.php +++ b/src/Symfony/Component/HttpClient/Response/ResponseTrait.php @@ -112,11 +112,15 @@ trait ResponseTrait } } - if (null === $content) { - throw new TransportException('Cannot get the content of the response twice: the request was issued with option "buffer" set to false.'); + 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: the request was issued with option "buffer" set to false.'); } foreach (self::stream([$this]) as $chunk) { diff --git a/src/Symfony/Component/HttpClient/Tests/MockHttpClientTest.php b/src/Symfony/Component/HttpClient/Tests/MockHttpClientTest.php index 32b4ebe448..f8f2c3e18b 100644 --- a/src/Symfony/Component/HttpClient/Tests/MockHttpClientTest.php +++ b/src/Symfony/Component/HttpClient/Tests/MockHttpClientTest.php @@ -48,7 +48,7 @@ class MockHttpClientTest extends HttpClientTestCase return new MockHttpClient(function (string $method, string $url, array $options) use ($client) { try { // force the request to be completed so that we don't test side effects of the transport - $response = $client->request($method, $url, $options); + $response = $client->request($method, $url, ['buffer' => false] + $options); $content = $response->getContent(false); return new MockResponse($content, $response->getInfo()); diff --git a/src/Symfony/Contracts/HttpClient/Test/Fixtures/web/index.php b/src/Symfony/Contracts/HttpClient/Test/Fixtures/web/index.php index 10ed100ccc..08dd1b6dca 100644 --- a/src/Symfony/Contracts/HttpClient/Test/Fixtures/web/index.php +++ b/src/Symfony/Contracts/HttpClient/Test/Fixtures/web/index.php @@ -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': @@ -143,4 +149,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; diff --git a/src/Symfony/Contracts/HttpClient/Test/HttpClientTestCase.php b/src/Symfony/Contracts/HttpClient/Test/HttpClientTestCase.php index df7a597590..e8d8b19eee 100644 --- a/src/Symfony/Contracts/HttpClient/Test/HttpClientTestCase.php +++ b/src/Symfony/Contracts/HttpClient/Test/HttpClientTestCase.php @@ -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()); } @@ -265,6 +263,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()); From 3bed0247c0b250c356ed9cc5b38c5fbaf23fa9a8 Mon Sep 17 00:00:00 2001 From: Denys Voronin Date: Wed, 16 Oct 2019 13:30:11 +0300 Subject: [PATCH 5/5] [Config] Disable default alphabet sorting in glob function due of unstable sort --- link | 2 +- src/Symfony/Component/Config/Resource/GlobResource.php | 4 +++- src/Symfony/Component/Finder/Finder.php | 3 ++- .../Translation/Resources/bin/translation-status.php | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/link b/link index 95a3142d2a..7b7512f0c9 100755 --- a/link +++ b/link @@ -64,6 +64,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); } diff --git a/src/Symfony/Component/Config/Resource/GlobResource.php b/src/Symfony/Component/Config/Resource/GlobResource.php index 28ba0a6112..13d2ee7d70 100644 --- a/src/Symfony/Component/Config/Resource/GlobResource.php +++ b/src/Symfony/Component/Config/Resource/GlobResource.php @@ -100,7 +100,9 @@ class GlobResource implements \IteratorAggregate, SelfCheckingResourceInterface, } 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->recursive && is_dir($path)) { $files = iterator_to_array(new \RecursiveIteratorIterator( new \RecursiveCallbackFilterIterator( diff --git a/src/Symfony/Component/Finder/Finder.php b/src/Symfony/Component/Finder/Finder.php index e933f07841..6624e84079 100644 --- a/src/Symfony/Component/Finder/Finder.php +++ b/src/Symfony/Component/Finder/Finder.php @@ -541,7 +541,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 \InvalidArgumentException(sprintf('The "%s" directory does not exist.', $dir)); diff --git a/src/Symfony/Component/Translation/Resources/bin/translation-status.php b/src/Symfony/Component/Translation/Resources/bin/translation-status.php index 669b8f2864..44918c92ec 100644 --- a/src/Symfony/Component/Translation/Resources/bin/translation-status.php +++ b/src/Symfony/Component/Translation/Resources/bin/translation-status.php @@ -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);