10000 Merge branch '6.4' into 7.0 · symfony/symfony@78adb40 · GitHub
[go: up one dir, main page]

Skip to content

Commit 78adb40

Browse files
committed
Merge branch '6.4' into 7.0
* 6.4: fix tests Drop test case Catch TableNotFoundException in MySQL delete [DoctrineBridge] Fix deprecation warning with ORM 3 when guessing field lengths Throw TransformationFailedException when there is a null bytes injection [Cache][Lock] Identify missing table in pgsql correctly and address failing integration tests [Mailer] [Brevo] Check that tags is present in payload before calling setTags [Serializer] Fix object normalizer when properties has the same name as their accessor
2 parents 968d80c + ed09ed1 commit 78adb40

File tree

18 files changed

+296
-37
lines changed

18 files changed

+296
-37
lines changed

src/Symfony/Bridge/Doctrine/Form/DoctrineOrmTypeGuesser.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Doctrine\DBAL\Types\Types;
1515
use Doctrine\ORM\Mapping\ClassMetadata;
1616
use Doctrine\ORM\Mapping\ClassMetadataInfo;
17+
use Doctrine\ORM\Mapping\FieldMapping;
1718
use Doctrine\ORM\Mapping\JoinColumnMapping;
1819
use Doctrine\ORM\Mapping\MappingException as LegacyMappingException;
1920
use Doctrine\Persistence\ManagerRegistry;
@@ -129,8 +130,10 @@ public function guessMaxLength(string $class, string $property): ?ValueGuess
129130
if ($ret && isset($ret[0]->fieldMappings[$property]) && !$ret[0]->hasAssociation($property)) {
130131
$mapping = $ret[0]->getFieldMapping($property);
131132

132-
if (isset($mapping['length'])) {
133-
return new ValueGuess($mapping['length'], Guess::HIGH_CONFIDENCE);
133+
$length = $mapping instanceof FieldMapping ? $mapping->length : ($mapping['length'] ?? null);
134+
135+
if (null !== $length) {
136+
return new ValueGuess($length, Guess::HIGH_CONFIDENCE);
134137
}
135138

136139
if (\in_array($ret[0]->getTypeOfField($property), [Types::DECIMAL, Types::FLOAT])) {

src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,19 +1314,6 @@ public function testPassIdAndNameToView()
13141314
$this->assertEquals('name', $view->vars['full_name']);
13151315
}
13161316

1317-
public function testStripLeadingUnderscoresAndDigitsFromId()
1318-
{
1319-
$view = $this->factory->createNamed('_09name', static::TESTED_TYPE, null, [
1320-
'em' => 'default',
1321-
'class' => self::SINGLE_IDENT_CLASS,
1322-
])
1323-
->createView();
1324-
1325-
$this->assertEquals('name', $view->vars['id']);
1326-
$this->assertEquals('_09name', $view->vars['name']);
1327-
$this->assertEquals('_09name', $view->vars['full_name']);
1328-
}
1329-
13301317
public function testPassIdAndNameToViewWithParent()
13311318
{
13321319
$view = $this->factory->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE)

src/Symfony/Bridge/Doctrine/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"symfony/dependency-injection": "^6.4|^7.0",
3030
"symfony/doctrine-messenger": "^6.4|^7.0",
3131
"symfony/expression-language": "^6.4|^7.0",
32-
"symfony/form": "^6.4|^7.0",
32+
"symfony/form": "^6.4.6|^7.0",
3333
"symfony/http-kernel": "^6.4|^7.0",
3434
"symfony/lock": "^6.4|^7.0",
3535
"symfony/messenger": "^6.4|^7.0",
@@ -53,7 +53,7 @@
5353
"doctrine/orm": "<2.15",
5454
"symfony/cache": "<6.4",
5555
"symfony/dependency-injection": "<6.4",
56-
"symfony/form": "<6.4",
56+
"symfony/form": "<6.4.6",
5757
"symfony/http-foundation": "<6.4",
5858
"symfony/http-kernel": "<6.4",
5959
"symfony/lock": "<6.4",

src/Symfony/Component/Cache/Adapter/PdoAdapter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,10 +372,10 @@ private function getServerVersion(): string
372372
private function isTableMissing(\PDOException $exception): bool
373373
{
374374
$driver = $this->getDriver();
375-
$code = $exception->errorInfo ? $exception->errorInfo[1] : $exception->getCode();
375+
[$sqlState, $code] = $exception->errorInfo ?? [null, $exception->getCode()];
376376

377377
return match ($driver) {
378-
'pgsql' => '42P01' === $code,
378+
'pgsql' => '42P01' === $sqlState,
379379
'sqlite' => str_contains($exception->getMessage(), 'no such table:'),
380380
'oci' => 942 === $code,
381381
'sqlsrv' => 208 === $code,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ public function reverseTransform(mixed $value): ?\DateTime
109109
throw new TransformationFailedException('Expected a string.');
110110
}
111111

112+
if (str_contains($value, "\0")) {
113+
throw new TransformationFailedException('Null bytes not allowed');
114+
}
115+
112116
$outputTz = new \DateTimeZone($this->outputTimezone);
113117
$dateTime = \DateTime::createFromFormat($this->parseFormat, $value, $outputTz);
114118

src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToStringTransformerTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,19 @@ public function testReverseTransformEmpty()
133133
$this->assertNull($reverseTransformer->reverseTransform(''));
134134
}
135135

136+
public function testReverseTransformWithNullBytes()
137+
{
138+
$transformer = new DateTimeToStringTransformer();
139+
140+
$nullByte = \chr(0);
141+
$value = '2024-03-15 21:11:00'.$nullByte;
142+
143+
$this->expectException(TransformationFailedException::class);
144+
$this->expectExceptionMessage('Null bytes not allowed');
145+
146+
$transformer->reverseTransform($value);
147+
}
148+
136149
public function testReverseTransformWithDifferentTimezones()
137150
{
138151
$reverseTransformer = new DateTimeToStringTransformer('America/New_York', 'Asia/Hong_Kong', 'Y-m-d H:i:s');

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,6 @@ public function testPassIdAndNameToView()
4040
$this->assertEquals('name', $view->vars['full_name']);
4141
}
4242

43-
public function testStripLeadingUnderscoresAndDigitsFromId()
44-
{
45-
$view = $this->factory->createNamed('_09name', $this->getTestedType(), null, $this->getTestOptions())
46-
->createView();
47-
48-
$this->assertEquals('name', $view->vars['id']);
49-
$this->assertEquals('_09name', $view->vars['name']);
50-
$this->assertEquals('_09name', $view->vars['full_name']);
51-
}
52-
5343
public function testPassIdAndNameToViewWithParent()
5444
{
5545
$view = $this->factory->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE)

src/Symfony/Component/Lock/Store/PdoStore.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,10 @@ private function getCurrentTimestampStatement(): string
232232
private function isTableMissing(\PDOException $exception): bool
233233
{
234234
$driver = $this->getDriver();
235-
$code = $exception->errorInfo ? $exception->errorInfo[1] : $exception->getCode();
235+
[$sqlState, $code] = $exception->errorInfo ?? [null, $exception->getCode()];
236236

237237
return match ($driver) {
238-
'pgsql' => '42P01' === $code,
238+
'pgsql' => '42P01' === $sqlState,
239239
'sqlite' => str_contains($exception->getMessage(), 'no such table:'),
240240
'oci' => 942 === $code,
241241
'sqlsrv' => 208 === $code,

src/Symfony/Component/Mailer/Bridge/Brevo/RemoteEvent/BrevoPayloadConverter.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ public function convert(array $payload): AbstractMailerEvent
6060

6161
$event->setDate($date);
6262
$event->setRecipientEmail($payload['email']);
63-
$event->setTags($payload['tags']);
63+
64+
if (isset($payload['tags'])) {
65+
$event->setTags($payload['tags']);
66+
}
6467

6568
return $event;
6669
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"id": 814119,
3+
"email": "example@gmail.com",
4+
"message-id": "<202305311313.92192897094@smtp-relay.mailin.fr>",
5+
"date": "2023-05-31 15:13:08",
6+
"event": "request",
7+
"subject": "Subject Line",
8+
"sending_ip": "127.0.0.1",
9+
"ts_event": 1685538788,
10+
"ts": 1685538788,
11+
"reason": "sent",
12+
"ts_epoch": 1685538788179
13+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
use Symfony\Component\RemoteEvent\Event\Mailer\MailerDeliveryEvent;
4+
5+
$wh = new MailerDeliveryEvent(MailerDeliveryEvent::RECEIVED, '<202305311313.92192897094@smtp-relay.mailin.fr>', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true, flags: JSON_THROW_ON_ERROR));
6+
$wh->setRecipientEmail('example@gmail.com');
7+
$wh->setDate(\DateTimeImmutable::createFromFormat('U', 1685538788));
8+
9+
return $wh;

src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/Connection.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ public function get(): ?array
154154
$this->driverConnection->delete($this->configuration['table_name'], ['delivered_at' => '9999-12-31 23:59:59']);
155155
} catch (DriverException $e) {
156156
// Ignore the exception
157+
} catch (TableNotFoundException $e) {
158+
if ($this->autoSetup) {
159+
$this->setup();
160+
}
157161
}
158162
}
159163

src/Symfony/Component/Serializer/Mapping/Loader/AttributeLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata): bool
125125

126126
$accessorOrMutator = preg_match('/^(get|is|has|set)(.+)$/i', $method->name, $matches);
127127
if ($accessorOrMutator) {
128-
$attributeName = lcfirst($matches[2]);
128+
$attributeName = $reflectionClass->hasProperty($method->name) ? $method->name : lcfirst($matches[2]);
129129

130130
if (isset($attributesMetadata[$attributeName])) {
131131
$attributeMetadata = $attributesMetadata[$attributeName];

src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,25 @@ protected function extractAttributes(object $object, ?string $format = null, arr
7878

7979
if (str_starts_with($name, 'get') || str_starts_with($name, 'has') || str_starts_with($name, 'can')) {
8080
// getters, hassers and canners
81-
$attributeName = substr($name, 3);
81+
$attributeName = $name;
8282

8383
if (!$reflClass->hasProperty($attributeName)) {
84-
$attributeName = lcfirst($attributeName);
84+
$attributeName = substr($attributeName, 3);
85+
86+
if (!$reflClass->hasProperty($attributeName)) {
87+
$attributeName = lcfirst($attributeName);
88+
}
8589
}
8690
} elseif (str_starts_with($name, 'is')) {
8791
// issers
88-
$attributeName = substr($name, 2);
92+
$attributeName = $name;
8993

9094
if (!$reflClass->hasProperty($attributeName)) {
91-
$attributeName = lcfirst($attributeName);
95+
$attributeName = substr($attributeName, 2);
96+
97+
if (!$reflClass->hasProperty($attributeName)) {
98+
$attributeName = lcfirst($attributeName);
99+
}
92100
}
93101
}
94102

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Serializer\Tests\Fixtures;
13+
14+
class SamePropertyAsMethodDummy
15+
{
16+
private $freeTrial;
17+
private $hasSubscribe;
18+
private $getReady;
19+
private $isActive;
20+
21+
public function __construct($freeTrial, $hasSubscribe, $getReady, $isActive)
22+
{
23+
$this->freeTrial = $freeTrial;
24+
$this->hasSubscribe = $hasSubscribe;
25+
$this->getReady = $getReady;
26+
$this->isActive = $isActive;
27+
}
28+
29+
public function getFreeTrial()
30+
{
31+
return $this->freeTrial;
32+
}
33+
34+
public function hasSubscribe()
35+
{
36+
return $this->hasSubscribe;
37+
}
38+
39+
public function getReady()
40+
{
41+
return $this->getReady;
42+
}
43+
44+
public function isActive()
45+
{
46+
return $this->isActive;
47+
}
48+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Serializer\Tests\Fixtures;
13+
14+
use Symfony\Component\Serializer\Annotation\SerializedName;
15+
16+
class SamePropertyAsMethodWithMethodSerializedNameDummy
17+
{
18+
private $freeTrial;
19+
private $hasSubscribe;
20+
private $getReady;
21+
private $isActive;
22+
23+
public function __construct($freeTrial, $hasSubscribe, $getReady, $isActive)
24+
{
25+
$this->freeTrial = $freeTrial;
26+
$this->hasSubscribe = $hasSubscribe;
27+
$this->getReady = $getReady;
28+
$this->isActive = $isActive;
29+
}
30+
31+
/**
32+
* @SerializedName("free_trial_method")
33+
*/
34+
public function getFreeTrial()
35+
{
36+
return $this->freeTrial;
37+
}
38+
39+
/**
40+
* @SerializedName("has_subscribe_method")
41+
*/
42+
public function hasSubscribe()
43+
{
44+
return $this->hasSubscribe;
45+
}
46+
47+
/**
48+
* @SerializedName("get_ready_method")
49+
*/
50+
public function getReady()
51+
{
52+
return $this->getReady;
53+
}
54+
55+
/**
56+
* @SerializedName("is_active_method")
57+
*/
58+
public function isActive()
59+
{
60+
return $this->isActive;
61+
}
62+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Serializer\Tests\Fixtures;
13+
14+
use Symfony\Component\Serializer\Annotation\SerializedName;
15+
16+
class SamePropertyAsMethodWithPropertySerializedNameDummy
17+
{
18+
/**
19+
* @SerializedName("free_trial_property")
20+
*/
21+
private $freeTrial;
22+
23+
/**
24+
* @SerializedName("has_subscribe_property")
25+
*/
26+
private $hasSubscribe;
27+
28+
/**
29+
* @SerializedName("get_ready_property")
30+
*/
31+
private $getReady;
32+
33+
/**
34+
* @SerializedName("is_active_property")
35+
*/
36+
private $isActive;
37+
38+
public function __construct($freeTrial, $hasSubscribe, $getReady, $isActive)
39+
{
40+
$this->freeTrial = $freeTrial;
41+
$this->hasSubscribe = $hasSubscribe;
42+
$this->getReady = $getReady;
43+
$this->isActive = $isActive;
44+
}
45+
46+
public function getFreeTrial()
47+
{
48+
return $this->freeTrial;
49+
}
50+
51+
public function hasSubscribe()
52+
{
53+
return $this->hasSubscribe;
54+
}
55+
56+
public function getReady()
57+
{
58+
return $this->getReady;
59+
}
60+
61+
public function isActive()
62+
{
63+
return $this->isActive;
64+
}
65+
}

0 commit comments

Comments
 (0)
0