Skip to content

Commit 56847a7

Browse files
committed
Merge branch '4.4' into 5.1
* 4.4: Fix parameter order [DependencyInjection] Fix circular in DI with lazy + byContruct loop adjust Client::getProfile() typehint fix: resolving pt translation issues Update VERSION for 3.4.47 Update CONTRIBUTORS for 3.4.47 Update CHANGELOG for 3.4.47 Add Romanian missing translations [DependencyInjection][Translator] Silent deprecation triggered by libxml_disable_entity_loader fix lexing strings containing escaped quotation characters prevent duplicated error message for file upload limits ignore the pattern attribute for textareas fix: solving pt-br translation issues
2 parents f41a8e3 + 214e940 commit 56847a7

File tree

8 files changed

+272
-6
lines changed

8 files changed

+272
-6
lines changed

Extension/Core/Type/FileType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
namespace Symfony\Component\Form\Extension\Core\Type;
1313

1414
use Symfony\Component\Form\AbstractType;
15+
use Symfony\Component\Form\FileUploadError;
1516
use Symfony\Component\Form\FormBuilderInterface;
16-
use Symfony\Component\Form\FormError;
1717
use Symfony\Component\Form\FormEvent;
1818
use Symfony\Component\Form\FormEvents;
1919
use Symfony\Component\Form\FormInterface;
@@ -164,7 +164,7 @@ private function getFileUploadError(int $errorCode)
164164
$message = strtr($messageTemplate, $messageParameters);
165165
}
166166

167-
return new FormError($message, $messageTemplate, $messageParameters);
167+
return new FileUploadError($message, $messageTemplate, $messageParameters);
168168
}
169169

170170
/**

Extension/Core/Type/TextareaType.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class TextareaType extends AbstractType
2323
public function buildView(FormView $view, FormInterface $form, array $options)
2424
{
2525
$view->vars['pattern'] = null;
26+
unset($view->vars['attr']['pattern']);
2627
}
2728

2829
/**

Extension/Validator/ViolationMapper/ViolationMapper.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111

1212
namespace Symfony\Component\Form\Extension\Validator\ViolationMapper;
1313

14+
use Symfony\Component\Form\FileUploadError;
1415
use Symfony\Component\Form\FormError;
1516
use Symfony\Component\Form\FormInterface;
1617
use Symfony\Component\Form\Util\InheritDataAwareIterator;
1718
use Symfony\Component\PropertyAccess\PropertyPathBuilder;
1819
use Symfony\Component\PropertyAccess\PropertyPathIterator;
1920
use Symfony\Component\PropertyAccess\PropertyPathIteratorInterface;
21+
use Symfony\Component\Validator\Constraints\File;
2022
use Symfony\Component\Validator\ConstraintViolation;
2123

2224
/**
@@ -124,6 +126,23 @@ public function mapViolation(ConstraintViolation $violation, FormInterface $form
124126

125127
// Only add the error if the form is synchronized
126128
if ($this->acceptsErrors($scope)) {
129+
if ($violation->getConstraint() instanceof File && (string) \UPLOAD_ERR_INI_SIZE === $violation->getCode()) {
130+
$errorsTarget = $scope;
131+
132+
while (null !== $errorsTarget->getParent() && $errorsTarget->getConfig()->getErrorBubbling()) {
133+
$errorsTarget = $errorsTarget->getParent();
134+
}
135+
136+
$errors = $errorsTarget->getErrors();
137+
$errorsTarget->clearErrors();
138+
139+
foreach ($errors as $error) {
140+
if (!$error instanceof FileUploadError) {
141+
$errorsTarget->addError($error);
142+
}
143+
}
144+
}
145+
127146
$scope->addError(new FormError(
128147
$violation->getMessage(),
129148
$violation->getMessageTemplate(),

FileUploadError.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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\Form;
13+
14+
/**
15+
* @internal
16+
*/
17+
class FileUploadError extends FormError
18+
{
19+
}

Resources/translations/validators.ro.xlf

Lines changed: 123 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,136 @@
44
<body>
55
<trans-unit id="28">
66
<source>This form should not contain extra fields.</source>
7-
<target>Aceast formular nu ar trebui să conțină câmpuri suplimentare.</target>
7+
<target>Acest formular nu ar trebui să conțină câmpuri suplimentare.</target>
88
</trans-unit>
99
<trans-unit id="29">
1010
<source>The uploaded file was too large. Please try to upload a smaller file.</source>
1111
<target>Fișierul încărcat a fost prea mare. Vă rugăm sa încărcați un fișier mai mic.</target>
1212
</trans-unit>
1313
<trans-unit id="30">
1414
<source>The CSRF token is invalid. Please try to resubmit the form.</source>
15-
<target>Token-ul CSRF este invalid. Vă rugăm să trimiteți formularul incă o dată.</target>
15+
<target>Token-ul CSRF este invalid. Vă rugăm să retrimiteți formularul.</target>
16+
</trans-unit>
17+
<trans-unit id="99">
18+
<source>This value is not a valid HTML5 color.</source>
19+
<target>Această valoare nu este un cod de culoare HTML5 valid.</target>
20+
</trans-unit>
21+
<trans-unit id="100">
22+
<source>Please enter a valid birthdate.</source>
23+
<target>Vă rugăm să introduceți o dată de naștere validă.</target>
24+
</trans-unit>
25+
<trans-unit id="101">
26+
<source>The selected choice is invalid.</source>
27+
<target>Valoarea selectată este invalidă.</target>
28+
</trans-unit>
29+
<trans-unit id="102">
30+
<source>The collection is invalid.</source>
31+
<target>Colecția nu este validă.</target>
32+
</trans-unit>
33+
<trans-unit id="103">
34+
<source>Please select a valid color.</source>
35+
<target>Vă rugăm să selectați o culoare validă.</target>
36+
</trans-unit>
37+
<trans-unit id="104">
38+
<source>Please select a valid country.</source>
39+
<target>Vă rugăm să selectați o țară validă.</target>
40+
</trans-unit>
41+
<trans-unit id="105">
42+
<source>Please select a valid currency.</source>
43+
<target>Vă rugăm să selectați o monedă validă.</target>
44+
</trans-unit>
45+
<trans-unit id="106">
46+
<source>Please choose a valid date interval.</source>
47+
<target>Vă rugăm să selectați un interval de zile valid.</target>
48+
</trans-unit>
49+
<trans-unit id="107">
50+
<source>Please enter a valid date and time.</source>
51+
<target>Vă rugăm să introduceți o dată și o oră validă.</target>
52+
</trans-unit>
53+
<trans-unit id="108">
54+
<source>Please enter a valid date.</source>
55+
<target>Vă rugăm să introduceți o dată validă.</target>
56+
</trans-unit>
57+
<trans-unit id="109">
58+
<source>Please select a valid file.</source>
59+
<target>Vă rugăm să selectați un fișier valid.</target>
60+
</trans-unit>
61+
<trans-unit id="110">
62+
<source>The hidden field is invalid.</source>
63+
<target>Câmpul ascuns este invalid.</target>
64+
</trans-unit>
65+
<trans-unit id="111">
66+
<source>Please enter an integer.</source>
67+
<target>Vă rugăm să introduceți un număr întreg.</target>
68+
</trans-unit>
69+
<trans-unit id="112">
70+
<source>Please select a valid language.</source>
71+
<target>Vă rugăm să selectați o limbă validă.</target>
72+
</trans-unit>
73+
<trans-unit id="113">
74+
<source>Please select a valid locale.</source>
75+
<target>Vă rugăm să selectați o setare locală validă.</target>
76+
</trans-unit>
77+
<trans-unit id="114">
78+
<source>Please enter a valid money amount.</source>
79+
<target>Vă rugăm să introduceți o valoare monetară corectă.</target>
80+
</trans-unit>
81+
<trans-unit id="115">
82+
<source>Please enter a number.</source>
83+
<target>Vă rugăm să introduceți un număr.</target>
84+
</trans-unit>
85+
<trans-unit id="116">
86+
<source>The password is invalid.</source>
87+
<target>Parola nu este validă.</target>
88+
</trans-unit>
89+
<trans-unit id="117">
90+
<source>Please enter a percentage value.</source>
91+
<target>Vă rugăm să introduceți o valoare procentuală.</target>
92+
</trans-unit>
93+
<trans-unit id="118">
94+
<source>The values do not match.</source>
95+
<target>Valorile nu coincid.</target>
96+
</trans-unit>
97+
<trans-unit id="119">
98+
<source>Please enter a valid time.</source>
99+
<target>Vă rugăm să introduceți o oră validă.</target>
100+
</trans-unit>
101+
<trans-unit id="120">
102+
<source>Please select a valid timezone.</source>
103+
<target>Vă rugăm să selectați un fus orar valid.</target>
104+
</trans-unit>
105+
<trans-unit id="121">
106+
<source>Please enter a valid URL.</source>
107+
<target>Vă rugăm să introduceți un URL valid.</target>
108+
</trans-unit>
109+
<trans-unit id="122">
110+
<source>Please enter a valid search term.</source>
111+
<target>Vă rugăm să introduceți un termen de căutare valid.</target>
112+
</trans-unit>
113+
<trans-unit id="123">
114+
<source>Please provide a valid phone number.</source>
115+
<target>Vă rugăm să introduceți un număr de telefon valid.</target>
116+
</trans-unit>
117+
<trans-unit id="124">
118+
<source>The checkbox has an invalid value.</source>
119+
<target>Bifa nu are o valoare validă.</target>
120+
</trans-unit>
121+
<trans-unit id="125">
122+
<source>Please enter a valid email address.</source>
123+
<target>Vă rugăm să introduceți o adresă de email validă.</target>
124+
</trans-unit>
125+
<trans-unit id="126">
126+
<source>Please select a valid option.</source>
127+
<target>Vă rugăm să selectați o opțiune validă.</target>
128+
</trans-unit>
129+
<trans-unit id="127">
130+
<source>Please select a valid range.</source>
131+
<target>Vă rugăm să selectați un interval valid.</target>
132+
</trans-unit>
133+
<trans-unit id="128">
134+
<source>Please enter a valid week.</source>
135+
<target>Vă rugăm să introduceți o săptămână validă.</target>
16136
</trans-unit>
17137
</body>
18138
</file>
19-
</xliff>
139+
</xliff>

Tests/AbstractLayoutTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2045,7 +2045,7 @@ public function testTextarea()
20452045
$this->assertWidgetMatchesXpath($form->createView(), [],
20462046
'/textarea
20472047
[@name="name"]
2048-
[@pattern="foo"]
2048+
[not(@pattern)]
20492049
[.="foo&bar"]
20502050
'
20512051
);

Tests/Extension/Validator/ViolationMapper/ViolationMapperTest.php

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818
use Symfony\Component\Form\Exception\TransformationFailedException;
1919
use Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper;
2020
use Symfony\Component\Form\Extension\Validator\ViolationMapper\ViolationMapper;
21+
use Symfony\Component\Form\FileUploadError;
2122
use Symfony\Component\Form\Form;
2223
use Symfony\Component\Form\FormConfigBuilder;
2324
use Symfony\Component\Form\FormError;
2425
use Symfony\Component\Form\FormInterface;
2526
use Symfony\Component\Form\Tests\Extension\Validator\ViolationMapper\Fixtures\Issue;
2627
use Symfony\Component\PropertyAccess\PropertyPath;
28+
use Symfony\Component\Validator\Constraints\File;
2729
use Symfony\Component\Validator\ConstraintViolation;
2830
use Symfony\Component\Validator\ConstraintViolationInterface;
2931

@@ -81,6 +83,7 @@ protected function getForm($name = 'name', $propertyPath = null, $dataClass = nu
8183
$config->setPropertyPath($propertyPath);
8284
$config->setCompound(true);
8385
$config->setDataMapper(new PropertyPathMapper());
86+
$config->setErrorBubbling($options['error_bubbling'] ?? false);
8487

8588
if (!$synchronized) {
8689
$config->addViewTransformer(new CallbackTransformer(
@@ -1590,4 +1593,93 @@ public function testBacktrackIfSeveralSubFormsWithSamePropertyPath()
15901593
$this->assertEquals([$this->getFormError($violation2, $grandChild2)], iterator_to_array($grandChild2->getErrors()), $grandChild2->getName().' should have an error, but has none');
15911594
$this->assertEquals([$this->getFormError($violation3, $grandChild3)], iterator_to_array($grandChild3->getErrors()), $grandChild3->getName().' should have an error, but has none');
15921595
}
1596+
1597+
public function testFileUploadErrorIsNotRemovedIfNoFileSizeConstraintViolationWasRaised()
1598+
{
1599+
$form = $this->getForm('form');
1600+
$form->addError(new FileUploadError(
1601+
'The file is too large. Allowed maximum size is 2 MB.',
1602+
'The file is too large. Allowed maximum size is {{ limit }} {{ suffix }}.',
1603+
[
1604+
'{{ limit }}' => '2',
1605+
'{{ suffix }}' => 'MB',
1606+
]
1607+
));
1608+
1609+
$this->mapper->mapViolation($this->getConstraintViolation('data'), $form);
1610+
1611+
$this->assertCount(2, $form->getErrors());
1612+
}
1613+
1614+
public function testFileUploadErrorIsRemovedIfFileSizeConstraintViolationWasRaised()
1615+
{
1616+
$form = $this->getForm('form');
1617+
$form->addError(new FileUploadError(
1618+
'The file is too large. Allowed maximum size is 2 MB.',
1619+
'The file is too large. Allowed maximum size is {{ limit }} {{ suffix }}.',
1620+
[
1621+
'{{ limit }}' => '2',
1622+
'{{ suffix }}' => 'MB',
1623+
]
1624+
));
1625+
1626+
$violation = new ConstraintViolation(
1627+
'The file is too large (3 MB). Allowed maximum size is 2 MB.',
1628+
'The file is too large ({{ size }} {{ suffix }}). Allowed maximum size is {{ limit }} {{ suffix }}.',
1629+
[
1630+
'{{ limit }}' => '2',
1631+
'{{ size }}' => '3',
1632+
'{{ suffix }}' => 'MB',
1633+
],
1634+
'',
1635+
'data',
1636+
null,
1637+
null,
1638+
(string) \UPLOAD_ERR_INI_SIZE,
1639+
new File()
1640+
);
1641+
$this->mapper->mapViolation($this->getConstraintViolation('data'), $form);
1642+
$this->mapper->mapViolation($violation, $form);
1643+
1644+
$this->assertCount(2, $form->getErrors());
1645+
}
1646+
1647+
public function testFileUploadErrorIsRemovedIfFileSizeConstraintViolationWasRaisedOnFieldWithErrorBubbling()
1648+
{
1649+
$parent = $this->getForm('parent');
1650+
$child = $this->getForm('child', 'file', null, [], false, true, [
1651+
'error_bubbling' => true,
1652+
]);
1653+
$parent->add($child);
1654+
$child->addError(new FileUploadError(
1655+
'The file is too large. Allowed maximum size is 2 MB.',
1656+
'The file is too large. Allowed maximum size is {{ limit }} {{ suffix }}.',
1657+
[
1658+
'{{ limit }}' => '2',
1659+
'{{ suffix }}' => 'MB',
1660+
]
1661+
));
1662+
1663+
$violation = new ConstraintViolation(
1664+
'The file is too large (3 MB). Allowed maximum size is 2 MB.',
1665+
'The file is too large ({{ size }} {{ suffix }}). Allowed maximum size is {{ limit }} {{ suffix }}.',
1666+
[
1667+
'{{ limit }}' => '2',
1668+
'{{ size }}' => '3',
1669+
'{{ suffix }}' => 'MB',
1670+
],
1671+
null,
1672+
'data.file',
1673+
null,
1674+
null,
1675+
(string) \UPLOAD_ERR_INI_SIZE,
1676+
new File()
1677+
);
1678+
$this->mapper->mapViolation($this->getConstraintViolation('data'), $parent);
1679+
$this->mapper->mapViolation($this->getConstraintViolation('data.file'), $parent);
1680+
$this->mapper->mapViolation($violation, $parent);
1681+
1682+
$this->assertCount(3, $parent->getErrors());
1683+
$this->assertCount(0, $child->getErrors());
1684+
}
15931685
}

Tests/Resources/TranslationFilesTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,21 @@ public function testTranslationFileIsValid($filePath)
2929
$this->assertCount(0, $errors, sprintf('"%s" is invalid:%s', $filePath, \PHP_EOL.implode(\PHP_EOL, array_column($errors, 'message'))));
3030
}
3131

32+
/**
33+
* @dataProvider provideTranslationFiles
34+
* @group Legacy
35+
*/
36+
public function testTranslationFileIsValidWithoutEntityLoader($filePath)
37+
{
38+
$document = new \DOMDocument();
39+
$document->loadXML(file_get_contents($filePath));
40+
libxml_disable_entity_loader(true);
41+
42+
$errors = XliffUtils::validateSchema($document);
43+
44+
$this->assertCount(0, $errors, sprintf('"%s" is invalid:%s', $filePath, \PHP_EOL.implode(\PHP_EOL, array_column($errors, 'message'))));
45+
}
46+
3247
public function provideTranslationFiles()
3348
{
3449
return array_map(

0 commit comments

Comments
 (0)