From 20971dff8297d59c8cd4bc5f2ba604a4c13913c8 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Tue, 10 Mar 2020 20:37:52 +0100 Subject: [PATCH 1/3] ignore microseconds submitted by Edge --- .../Form/Extension/Core/Type/TimeType.php | 20 ++++---- .../Extension/Core/Type/TimeTypeTest.php | 48 +++++++++++++++++++ 2 files changed, 59 insertions(+), 9 deletions(-) diff --git a/src/Symfony/Component/Form/Extension/Core/Type/TimeType.php b/src/Symfony/Component/Form/Extension/Core/Type/TimeType.php index f0b5ac2ac4..2fcf200518 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/TimeType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/TimeType.php @@ -57,16 +57,18 @@ class TimeType extends AbstractType if ('single_text' === $options['widget']) { $builder->addViewTransformer(new DateTimeToStringTransformer($options['model_timezone'], $options['view_timezone'], $format)); - // handle seconds ignored by user's browser when with_seconds enabled - // https://codereview.chromium.org/450533009/ - if ($options['with_seconds']) { - $builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $e) { - $data = $e->getData(); - if ($data && preg_match('/^\d{2}:\d{2}$/', $data)) { - $e->setData($data.':00'); + $builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $e) use ($options) { + $data = $e->getData(); + if ($data && preg_match('/^(?P\d{2}):(?P\d{2})(?::(?P\d{2})(?:\.\d+)?)?$/', $data, $matches)) { + if ($options['with_seconds']) { + // handle seconds ignored by user's browser when with_seconds enabled + // https://codereview.chromium.org/450533009/ + $e->setData(sprintf('%s:%s:%s', $matches['hours'], $matches['minutes'], isset($matches['seconds']) ? $matches['seconds'] : '00')); + } else { + $e->setData(sprintf('%s:%s', $matches['hours'], $matches['minutes'])); } - }); - } + } + }); } else { $hourOptions = $minuteOptions = $secondOptions = [ 'error_bubbling' => true, diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php index 1f0797f000..3a911de8fe 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php @@ -239,6 +239,54 @@ class TimeTypeTest extends BaseTypeTest $this->assertEquals('03:04:00', $form->getViewData()); } + public function testSubmitWithoutSecondsAndBrowserAddingSeconds() + { + $form = $this->factory->create(static::TESTED_TYPE, null, [ + 'model_timezone' => 'UTC', + 'view_timezone' => 'UTC', + 'input' => 'string', + 'widget' => 'single_text', + 'with_seconds' => false, + ]); + + $form->submit('03:04:00'); + + $this->assertEquals('03:04:00', $form->getData()); + $this->assertEquals('03:04', $form->getViewData()); + } + + public function testSubmitWithSecondsAndBrowserAddingMicroseconds() + { + $form = $this->factory->create(static::TESTED_TYPE, null, [ + 'model_timezone' => 'UTC', + 'view_timezone' => 'UTC', + 'input' => 'string', + 'widget' => 'single_text', + 'with_seconds' => true, + ]); + + $form->submit('03:04:00.000'); + + $this->assertEquals('03:04:00', $form->getData()); + $this->assertEquals('03:04:00', $form->getViewData()); + } + + public function testSubmitWithoutSecondsAndBrowserAddingMicroseconds() + { + $form = $this->factory->create(static::TESTED_TYPE, null, [ + 'model_timezone' => 'UTC', + 'view_timezone' => 'UTC', + 'input' => 'string', + 'widget' => 'single_text', + 'with_seconds' => false, + ]); + + $form->submit('03:04:00.000'); + + $this->assertEquals('03:04:00', $form->getData()); + $this->assertEquals('03:04', $form->getViewData()); + } + public function testSetDataWithoutMinutes() { $form = $this->factory->create(static::TESTED_TYPE, null, [ From 453078ff37a6019d5862056ed0421d04af3f8295 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillaume=20P=C3=A9delagrabe?= Date: Wed, 11 Mar 2020 13:15:35 +0100 Subject: [PATCH 2/3] [Mime] Fix boundary header --- .../Component/Mime/Part/AbstractMultipartPart.php | 2 +- .../Mime/Tests/Part/Multipart/FormDataPartTest.php | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Mime/Part/AbstractMultipartPart.php b/src/Symfony/Component/Mime/Part/AbstractMultipartPart.php index 48b8620232..685d250627 100644 --- a/src/Symfony/Component/Mime/Part/AbstractMultipartPart.php +++ b/src/Symfony/Component/Mime/Part/AbstractMultipartPart.php @@ -91,7 +91,7 @@ abstract class AbstractMultipartPart extends AbstractPart private function getBoundary(): string { if (null === $this->boundary) { - $this->boundary = '_=_symfony_'.time().'_'.bin2hex(random_bytes(16)).'_=_'; + $this->boundary = strtr(base64_encode(random_bytes(6)), '+/', '-_'); } return $this->boundary; diff --git a/src/Symfony/Component/Mime/Tests/Part/Multipart/FormDataPartTest.php b/src/Symfony/Component/Mime/Tests/Part/Multipart/FormDataPartTest.php index a74ecea316..dbc2e6eff9 100644 --- a/src/Symfony/Component/Mime/Tests/Part/Multipart/FormDataPartTest.php +++ b/src/Symfony/Component/Mime/Tests/Part/Multipart/FormDataPartTest.php @@ -91,4 +91,16 @@ class FormDataPartTest extends TestCase $this->assertEquals($foo, $parts[0]->bodyToString()); $this->assertEquals($bar, $parts[1]->bodyToString()); } + + public function testBoundaryContentTypeHeader() + { + $f = new FormDataPart([ + 'file' => new DataPart('data.csv', 'data.csv', 'text/csv'), + ]); + $headers = $f->getPreparedHeaders()->toArray(); + $this->assertRegExp( + '/^Content-Type: multipart\/form-data; boundary=[a-zA-Z0-9\-_]{8}$/', + $headers[0] + ); + } } From 186ee831d706496c28aaee2d70355e231954470c Mon Sep 17 00:00:00 2001 From: Matthieu Mota Date: Sat, 14 Mar 2020 19:44:21 +0100 Subject: [PATCH 3/3] [HttpClient] Fix typo --- src/Symfony/Component/HttpClient/CurlHttpClient.php | 2 +- src/Symfony/Component/HttpClient/HttpClient.php | 2 +- src/Symfony/Component/HttpClient/NativeHttpClient.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/HttpClient/CurlHttpClient.php b/src/Symfony/Component/HttpClient/CurlHttpClient.php index b037ca0fc2..d20d8b6f32 100644 --- a/src/Symfony/Component/HttpClient/CurlHttpClient.php +++ b/src/Symfony/Component/HttpClient/CurlHttpClient.php @@ -53,7 +53,7 @@ final class CurlHttpClient implements HttpClientInterface, LoggerAwareInterface, private static $curlVersion; /** - * @param array $defaultOptions Default requests' options + * @param array $defaultOptions Default request's options * @param int $maxHostConnections The maximum number of connections to a single host * @param int $maxPendingPushes The maximum number of pushed responses to accept in the queue * diff --git a/src/Symfony/Component/HttpClient/HttpClient.php b/src/Symfony/Component/HttpClient/HttpClient.php index 3eb3a4c884..b8ce62a233 100644 --- a/src/Symfony/Component/HttpClient/HttpClient.php +++ b/src/Symfony/Component/HttpClient/HttpClient.php @@ -21,7 +21,7 @@ use Symfony\Contracts\HttpClient\HttpClientInterface; final class HttpClient { /** - * @param array $defaultOptions Default requests' options + * @param array $defaultOptions Default request's options * @param int $maxHostConnections The maximum number of connections to a single host * @param int $maxPendingPushes The maximum number of pushed responses to accept in the queue * diff --git a/src/Symfony/Component/HttpClient/NativeHttpClient.php b/src/Symfony/Component/HttpClient/NativeHttpClient.php index 2cdb202922..90524db1ae 100644 --- a/src/Symfony/Component/HttpClient/NativeHttpClient.php +++ b/src/Symfony/Component/HttpClient/NativeHttpClient.php @@ -41,7 +41,7 @@ final class NativeHttpClient implements HttpClientInterface, LoggerAwareInterfac private $multi; /** - * @param array $defaultOptions Default requests' options + * @param array $defaultOptions Default request's options * @param int $maxHostConnections The maximum number of connections to open * * @see HttpClientInterface::OPTIONS_DEFAULTS for available options