Skip to content

Commit d37ecc7

Browse files
Merge branch '4.4' into 5.4
* 4.4: Remove former core members from code owners [Form] fix populating single widget time view data with different timezones [DomCrawler][VarDumper] Fix html-encoding emojis
2 parents 4f8d787 + ce4a1a9 commit d37ecc7

File tree

7 files changed

+88
-12
lines changed

7 files changed

+88
-12
lines changed

.github/CODEOWNERS

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,8 @@
2424
/src/Symfony/Component/Form/ @xabbuh @yceruto
2525
# HttpKernel
2626
/src/Symfony/Component/HttpKernel/Log/Logger.php @dunglas
27-
# LDAP
28-
/src/Symfony/Component/Ldap/ @csarrazi
2927
# Lock
3028
/src/Symfony/Component/Lock/ @jderusse
31-
# Messenger
32-
/src/Symfony/Bridge/Doctrine/Messenger/ @sroze
33-
/src/Symfony/Component/Messenger/ @sroze
3429
# Notifer
3530
/src/Symfony/Component/Notifier/ @OskarStark
3631
# OptionsResolver

src/Symfony/Component/DomCrawler/Crawler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,11 +1186,11 @@ private function convertToHtmlEntities(string $htmlContent, string $charset = 'U
11861186
set_error_handler(function () { throw new \Exception(); });
11871187

11881188
try {
1189-
return mb_encode_numericentity($htmlContent, [0x80, 0xFFFF, 0, 0xFFFF], $charset);
1189+
return mb_encode_numericentity($htmlContent, [0x80, 0x10FFFF, 0, 0x1FFFFF], $charset);
11901190
} catch (\Exception|\ValueError $e) {
11911191
try {
11921192
$htmlContent = iconv($charset, 'UTF-8', $htmlContent);
1193-
$htmlContent = mb_encode_numericentity($htmlContent, [0x80, 0xFFFF, 0, 0xFFFF], 'UTF-8');
1193+
$htmlContent = mb_encode_numericentity($htmlContent, [0x80, 0x10FFFF, 0, 0x1FFFFF], 'UTF-8');
11941194
} catch (\Exception|\ValueError $e) {
11951195
}
11961196

src/Symfony/Component/DomCrawler/Tests/AbstractCrawlerTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,13 @@ public function testHtml()
381381
$this->assertSame('my value', $this->createTestCrawler(null)->filterXPath('//ol')->html('my value'));
382382
}
383383

384+
public function testEmojis()
385+
{
386+
$crawler = $this->createCrawler('<body><p>Hey 👋</p></body>');
387+
388+
$this->assertSame('<body><p>Hey 👋</p></body>', $crawler->html());
389+
}
390+
384391
public function testExtract()
385392
{
386393
$crawler = $this->createTestCrawler()->filterXPath('//ul[1]/li');

src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToStringTransformer.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,14 @@ class DateTimeToStringTransformer extends BaseDateTimeTransformer
4747
* @param string|null $inputTimezone The name of the input timezone
4848
* @param string|null $outputTimezone The name of the output timezone
4949
* @param string $format The date format
50+
* @param string|null $parseFormat The parse format when different from $format
5051
*/
51-
public function __construct(string $inputTimezone = null, string $outputTimezone = null, string $format = 'Y-m-d H:i:s')
52+
public function __construct(string $inputTimezone = null, string $outputTimezone = null, string $format = 'Y-m-d H:i:s', string $parseFormat = null)
5253
{
5354
parent::__construct($inputTimezone, $outputTimezone);
5455

55-
$this->generateFormat = $this->parseFormat = $format;
56+
$this->generateFormat = $format;
57+
$this->parseFormat = $parseFormat ?? $format;
5658

5759
// See https://php.net/datetime.createfromformat
5860
// The character "|" in the format makes sure that the parts of a date

src/Symfony/Component/Form/Extension/Core/Type/TimeType.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@ public function buildForm(FormBuilderInterface $builder, array $options)
7474
}
7575
});
7676

77+
$parseFormat = null;
78+
7779
if (null !== $options['reference_date']) {
78-
$format = 'Y-m-d '.$format;
80+
$parseFormat = 'Y-m-d '.$format;
7981

8082
$builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) use ($options) {
8183
$data = $event->getData();
@@ -86,7 +88,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
8688
});
8789
}
8890

89-
$builder->addViewTransformer(new DateTimeToStringTransformer($options['model_timezone'], $options['view_timezone'], $format));
91+
$builder->addViewTransformer(new DateTimeToStringTransformer($options['model_timezone'], $options['view_timezone'], $format, $parseFormat));
9092
} else {
9193
$hourOptions = $minuteOptions = $secondOptions = [
9294
'error_bubbling' => true,

src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,76 @@ public function testSubmitWithSecondsAndBrowserOmissionSeconds()
280280
$this->assertEquals('03:04:00', $form->getViewData());
281281
}
282282

283+
public function testPreSetDataDifferentTimezones()
284+
{
285+
$form = $this->factory->create(static::TESTED_TYPE, null, [
286+
'model_timezone' => 'UTC',
287+
'view_timezone' => 'Europe/Berlin',
288+
'input' => 'datetime',
289+
'with_seconds' => true,
290+
'reference_date' => new \DateTimeImmutable('2019-01-01', new \DateTimeZone('UTC')),
291+
]);
292+
$form->setData(new \DateTime('2022-01-01 15:09:10', new \DateTimeZone('UTC')));
293+
294+
$this->assertSame('15:09:10', $form->getData()->format('H:i:s'));
295+
$this->assertSame([
296+
'hour' => '16',
297+
'minute' => '9',
298+
'second' => '10',
299+
], $form->getViewData());
300+
}
301+
302+
public function testPreSetDataDifferentTimezonesDuringDaylightSavingTime()
303+
{
304+
$form = $this->factory->create(static::TESTED_TYPE, null, [
305+
'model_timezone' => 'UTC',
306+
'view_timezone' => 'Europe/Berlin',
307+
'input' => 'datetime',
308+
'with_seconds' => true,
309+
'reference_date' => new \DateTimeImmutable('2019-07-12', new \DateTimeZone('UTC')),
310+
]);
311+
$form->setData(new \DateTime('2022-04-29 15:09:10', new \DateTimeZone('UTC')));
312+
313+
$this->assertSame('15:09:10', $form->getData()->format('H:i:s'));
314+
$this->assertSame([
315+
'hour' => '17',
316+
'minute' => '9',
317+
'second' => '10',
318+
], $form->getViewData());
319+
}
320+
321+
public function testPreSetDataDifferentTimezonesUsingSingleTextWidget()
322+
{
323+
$form = $this->factory->create(static::TESTED_TYPE, null, [
324+
'model_timezone' => 'UTC',
325+
'view_timezone' => 'Europe/Berlin',
326+
'input' => 'datetime',
327+
'with_seconds' => true,
328+
'reference_date' => new \DateTimeImmutable('2019-01-01', new \DateTimeZone('UTC')),
329+
'widget' => 'single_text',
330+
]);
331+
$form->setData(new \DateTime('2022-01-01 15:09:10', new \DateTimeZone('UTC')));
332+
333+
$this->assertSame('15:09:10', $form->getData()->format('H:i:s'));
334+
$this->assertSame('16:09:10', $form->getViewData());
335+
}
336+
337+
public function testPreSetDataDifferentTimezonesDuringDaylightSavingTimeUsingSingleTextWidget()
338+
{
339+
$form = $this->factory->create(static::TESTED_TYPE, null, [
340+
'model_timezone' => 'UTC',
341+
'view_timezone' => 'Europe/Berlin',
342+
'input' => 'datetime',
343+
'with_seconds' => true,
344+
'reference_date' => new \DateTimeImmutable('2019-07-12', new \DateTimeZone('UTC')),
345+
'widget' => 'single_text',
346+
]);
347+
$form->setData(new \DateTime('2022-04-29 15:09:10', new \DateTimeZone('UTC')));
348+
349+
$this->assertSame('15:09:10', $form->getData()->format('H:i:s'));
350+
$this->assertSame('17:09:10', $form->getViewData());
351+
}
352+
283353
public function testSubmitDifferentTimezones()
284354
{
285355
$form = $this->factory->create(static::TESTED_TYPE, null, [

src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ protected function dumpLine(int $depth, bool $endOfValue = false)
960960
}
961961
$this->lastDepth = $depth;
962962

963-
$this->line = mb_encode_numericentity($this->line, [0x80, 0xFFFF, 0, 0xFFFF], 'UTF-8');
963+
$this->line = mb_encode_numericentity($this->line, [0x80, 0x10FFFF, 0, 0x1FFFFF], 'UTF-8');
964964

965965
if (-1 === $depth) {
966966
AbstractDumper::dumpLine(0);

0 commit comments

Comments
 (0)