Skip to content

Commit b01ac08

Browse files
committed
Merge branch '5.1' into 5.2
* 5.1: Fix parameter order [DependencyInjection] Fix circular in DI with lazy + byContruct loop adjust Client::getProfile() typehint adjust KernelBrowser::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 6327575 + 56847a7 commit b01ac08

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;
@@ -169,7 +169,7 @@ private function getFileUploadError(int $errorCode)
169169
$message = strtr($messageTemplate, $messageParameters);
170170
}
171171

172-
return new FormError($message, $messageTemplate, $messageParameters);
172+
return new FileUploadError($message, $messageTemplate, $messageParameters);
173173
}
174174

175175
/**

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,13 +11,15 @@
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\FormRendererInterface;
1718
use Symfony\Component\Form\Util\InheritDataAwareIterator;
1819
use Symfony\Component\PropertyAccess\PropertyPathBuilder;
1920
use Symfony\Component\PropertyAccess\PropertyPathIterator;
2021
use Symfony\Component\PropertyAccess\PropertyPathIteratorInterface;
22+
use Symfony\Component\Validator\Constraints\File;
2123
use Symfony\Component\Validator\ConstraintViolation;
2224
use Symfony\Contracts\Translation\TranslatorInterface;
2325

@@ -131,6 +133,23 @@ public function mapViolation(ConstraintViolation $violation, FormInterface $form
131133

132134
// Only add the error if the form is synchronized
133135
if ($this->acceptsErrors($scope)) {
136+
if ($violation->getConstraint() instanceof File && (string) \UPLOAD_ERR_INI_SIZE === $violation->getCode()) {
137+
$errorsTarget = $scope;
138+
139+
while (null !== $errorsTarget->getParent() && $errorsTarget->getConfig()->getErrorBubbling()) {
140+
$errorsTarget = $errorsTarget->getParent();
141+
}
142+
143+
$errors = $errorsTarget->getErrors();
144+
$errorsTarget->clearErrors();
145+
146+
foreach ($errors as $error) {
147+
if (!$error instanceof FileUploadError) {
148+
$errorsTarget->addError($error);
149+
}
150+
}
151+
}
152+
134153
$message = $violation->getMessage();
135154
$messageTemplate = $violation->getMessageTemplate();
136155

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,13 +18,15 @@
1818
use Symfony\Component\Form\Exception\TransformationFailedException;
1919
use Symfony\Component\Form\Extension\Core\DataMapper\DataMapper;
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\FormRenderer;
2627
use Symfony\Component\Form\Tests\Extension\Validator\ViolationMapper\Fixtures\Issue;
2728
use Symfony\Component\PropertyAccess\PropertyPath;
29+
use Symfony\Component\Validator\Constraints\File;
2830
use Symfony\Component\Validator\ConstraintViolation;
2931
use Symfony\Component\Validator\ConstraintViolationInterface;
3032
use Symfony\Contracts\Translation\TranslatorInterface;
@@ -83,6 +85,7 @@ protected function getForm($name = 'name', $propertyPath = null, $dataClass = nu
8385
$config->setPropertyPath($propertyPath);
8486
$config->setCompound(true);
8587
$config->setDataMapper(new DataMapper());
88+
$config->setErrorBubbling($options['error_bubbling'] ?? false);
8689

8790
if (!$synchronized) {
8891
$config->addViewTransformer(new CallbackTransformer(
@@ -1759,4 +1762,93 @@ public function testTranslatorNotCalledWithoutLabel()
17591762
$violation = new ConstraintViolation('Message without label', null, [], null, 'data.name', null);
17601763
$this->mapper->mapViolation($violation, $parent);
17611764
}
1765+
1766+
public function testFileUploadErrorIsNotRemovedIfNoFileSizeConstraintViolationWasRaised()
1767+
{
1768+
$form = $this->getForm('form');
1769+
$form->addError(new FileUploadError(
1770+
'The file is too large. Allowed maximum size is 2 MB.',
1771+
'The file is too large. Allowed maximum size is {{ limit }} {{ suffix }}.',
1772+
[
1773+
'{{ limit }}' => '2',
1774+
'{{ suffix }}' => 'MB',
1775+
]
1776+
));
1777+
1778+
$this->mapper->mapViolation($this->getConstraintViolation('data'), $form);
1779+
1780+
$this->assertCount(2, $form->getErrors());
1781+
}
1782+
1783+
public function testFileUploadErrorIsRemovedIfFileSizeConstraintViolationWasRaised()
1784+
{
1785+
$form = $this->getForm('form');
1786+
$form->addError(new FileUploadError(
1787+
'The file is too large. Allowed maximum size is 2 MB.',
1788+
'The file is too large. Allowed maximum size is {{ limit }} {{ suffix }}.',
1789+
[
1790+
'{{ limit }}' => '2',
1791+
'{{ suffix }}' => 'MB',
1792+
]
1793+
));
1794+
1795+
$violation = new ConstraintViolation(
1796+
'The file is too large (3 MB). Allowed maximum size is 2 MB.',
1797+
'The file is too large ({{ size }} {{ suffix }}). Allowed maximum size is {{ limit }} {{ suffix }}.',
1798+
[
1799+
'{{ limit }}' => '2',
1800+
'{{ size }}' => '3',
1801+
'{{ suffix }}' => 'MB',
1802+
],
1803+
'',
1804+
'data',
1805+
null,
1806+
null,
1807+
(string) \UPLOAD_ERR_INI_SIZE,
1808+
new File()
1809+
);
1810+
$this->mapper->mapViolation($this->getConstraintViolation('data'), $form);
1811+
$this->mapper->mapViolation($violation, $form);
1812+
1813+
$this->assertCount(2, $form->getErrors());
1814+
}
1815+
1816+
public function testFileUploadErrorIsRemovedIfFileSizeConstraintViolationWasRaisedOnFieldWithErrorBubbling()
1817+
{
1818+
$parent = $this->getForm('parent');
1819+
$child = $this->getForm('child', 'file', null, [], false, true, [
1820+
'error_bubbling' => true,
1821+
]);
1822+
$parent->add($child);
1823+
$child->addError(new FileUploadError(
1824+
'The file is too large. Allowed maximum size is 2 MB.',
1825+
'The file is too large. Allowed maximum size is {{ limit }} {{ suffix }}.',
1826+
[
1827+
'{{ limit }}' => '2',
1828+
'{{ suffix }}' => 'MB',
1829+
]
1830+
));
1831+
1832+
$violation = new ConstraintViolation(
1833+
'The file is too large (3 MB). Allowed maximum size is 2 MB.',
1834+
'The file is too large ({{ size }} {{ suffix }}). Allowed maximum size is {{ limit }} {{ suffix }}.',
1835+
[
1836+
'{{ limit }}' => '2',
1837+
'{{ size }}' => '3',
1838+
'{{ suffix }}' => 'MB',
1839+
],
1840+
null,
1841+
'data.file',
1842+
null,
1843+
null,
1844+
(string) \UPLOAD_ERR_INI_SIZE,
1845+
new File()
1846+
);
1847+
$this->mapper->mapViolation($this->getConstraintViolation('data'), $parent);
1848+
$this->mapper->mapViolation($this->getConstraintViolation('data.file'), $parent);
1849+
$this->mapper->mapViolation($violation, $parent);
1850+
1851+
$this->assertCount(3, $parent->getErrors());
1852+
$this->assertCount(0, $child->getErrors());
1853+
}
17621854
}

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)