Skip to content

Commit bb4854c

Browse files
committed
Merge branch '6.4' into 7.0
* 6.4: initialize the current time with midnight before modifying the date fix tests [HtmlSanitizer] Ignore Processing Instructions
2 parents e928051 + 92c0d17 commit bb4854c

File tree

5 files changed

+34
-6
lines changed

5 files changed

+34
-6
lines changed

src/Symfony/Component/Clock/DatePoint.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,21 @@ public function __construct(string $datetime = 'now', ?\DateTimeZone $timezone =
3232

3333
if (\PHP_VERSION_ID < 80300) {
3434
try {
35-
$timezone = (new parent($datetime, $timezone ?? $now->getTimezone()))->getTimezone();
35+
$builtInDate = new parent($datetime, $timezone ?? $now->getTimezone());
36+
$timezone = $builtInDate->getTimezone();
3637
} catch (\Exception $e) {
3738
throw new \DateMalformedStringException($e->getMessage(), $e->getCode(), $e);
3839
}
3940
} else {
40-
$timezone = (new parent($datetime, $timezone ?? $now->getTimezone()))->getTimezone();
41+
$builtInDate = new parent($datetime, $timezone ?? $now->getTimezone());
42+
$timezone = $builtInDate->getTimezone();
4143
}
4244

4345
$now = $now->setTimezone($timezone)->modify($datetime);
46+
47+
if ('00:00:00.000000' === $builtInDate->format('H:i:s.u')) {
48+
$now = $now->setTime(0, 0);
49+
}
4450
} elseif (null !== $timezone) {
4551
$now = $now->setTimezone($timezone);
4652
}

src/Symfony/Component/Clock/Tests/DatePointTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,19 @@ public function testModify()
5757
$this->expectExceptionMessage('Failed to parse time string (Bad Date)');
5858
$date->modify('Bad Date');
5959
}
60+
61+
/**
62+
* @testWith ["2024-04-01 00:00:00.000000", "2024-04"]
63+
* ["2024-04-09 00:00:00.000000", "2024-04-09"]
64+
* ["2024-04-09 03:00:00.000000", "2024-04-09 03:00"]
65+
* ["2024-04-09 00:00:00.123456", "2024-04-09 00:00:00.123456"]
66+
*/
67+
public function testTimeDefaultsToMidnight(string $expected, string $datetime)
68+
{
69+
$date = new \DateTimeImmutable($datetime);
70+
$this->assertSame($expected, $date->format('Y-m-d H:i:s.u'));
71+
72+
$date = new DatePoint($datetime);
73+
$this->assertSame($expected, $date->format('Y-m-d H:i:s.u'));
74+
}
6075
}

src/Symfony/Component/HtmlSanitizer/Tests/HtmlSanitizerAllTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,12 @@ public static function provideSanitizeBody()
309309
'Lorem ipsum ',
310310
],
311311

312+
// Processing instructions
313+
[
314+
'Lorem ipsum<?div x?>foo',
315+
'Lorem ipsumfoo',
316+
],
317+
312318
// Normal tags
313319
[
314320
'<abbr>Lorem ipsum</abbr>',

src/Symfony/Component/HtmlSanitizer/Visitor/DomVisitor.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,10 @@ private function visitChildren(\DOMNode $domNode, Cursor $cursor): void
134134
if ('#text' === $child->nodeName) {
135135
// Add text directly for performance
136136
$cursor->node->addChild(new TextNode($cursor->node, $child->nodeValue));
137-
} elseif (!$child instanceof \DOMText) {
137+
} elseif (!$child instanceof \DOMText && !$child instanceof \DOMProcessingInstruction) {
138138
// Otherwise continue the visit recursively
139139
// Ignore comments for security reasons (interpreted differently by browsers)
140+
// Ignore processing instructions (treated as comments)
140141
$this->visitNode($child, $cursor);
141142
}
142143
}

src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/ConnectionTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ private function getDBALConnectionMock()
300300
$platform = $this->createMock(AbstractPlatform::class);
301301

302302
if (!method_exists(QueryBuilder::class, 'forUpdate')) {
303-
$platform->method('getWriteLockSQL')->willReturn('FOR UPDATE');
303+
$platform->method('getWriteLockSQL')->willReturn('FOR UPDATE SKIP LOCKED');
304304
}
305305

306306
$configuration = $this->createMock(\Doctrine\DBAL\Configuration::class);
@@ -573,7 +573,7 @@ class_exists(MySQLPlatform::class) ? new MySQLPlatform() : new MySQL57Platform()
573573

574574
yield 'SQL Server' => [
575575
class_exists(SQLServerPlatform::class) && !class_exists(SQLServer2012Platform::class) ? new SQLServerPlatform() : new SQLServer2012Platform(),
576-
'SELECT m.* FROM messenger_messages m WITH (UPDLOCK, ROWLOCK, READPAST) WHERE (m.queue_name = ?) AND (m.delivered_at is null OR m.delivered_at < ?) AND (m.available_at <= ?) ORDER BY available_at ASC OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY ',
576+
sprintf('SELECT m.* FROM messenger_messages m WITH (UPDLOCK, ROWLOCK%s) WHERE (m.queue_name = ?) AND (m.delivered_at is null OR m.delivered_at < ?) AND (m.available_at <= ?) ORDER BY available_at ASC OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY ', method_exists(QueryBuilder::class, 'forUpdate') ? ', READPAST' : ''),
577577
];
578578

579579
if (!class_exists(MySQL57Platform::class)) {
@@ -586,7 +586,7 @@ class_exists(SQLServerPlatform::class) && !class_exists(SQLServer2012Platform::c
586586
// DBAL < 4
587587
yield 'Oracle' => [
588588
new OraclePlatform(),
589-
'SELECT w.id AS "id", w.body AS "body", w.headers AS "headers", w.queue_name AS "queue_name", w.created_at AS "created_at", w.available_at AS "available_at", w.delivered_at AS "delivered_at" FROM messenger_messages w WHERE w.id IN (SELECT a.id FROM (SELECT m.id FROM messenger_messages m WHERE (m.queue_name = ?) AND (m.delivered_at is null OR m.delivered_at < ?) AND (m.available_at <= ?) ORDER BY available_at ASC) a WHERE ROWNUM <= 1) FOR UPDATE SKIP LOCKED',
589+
sprintf('SELECT w.id AS "id", w.body AS "body", w.headers AS "headers", w.queue_name AS "queue_name", w.created_at AS "created_at", w.available_at AS "available_at", w.delivered_at AS "delivered_at" FROM messenger_messages w WHERE w.id IN (SELECT a.id FROM (SELECT m.id FROM messenger_messages m WHERE (m.queue_name = ?) AND (m.delivered_at is null OR m.delivered_at < ?) AND (m.available_at <= ?) ORDER BY available_at ASC) a WHERE ROWNUM <= 1) FOR UPDATE%s', method_exists(QueryBuilder::class, 'forUpdate') ? ' SKIP LOCKED' : ''),
590590
];
591591
}
592592
}

0 commit comments

Comments
 (0)