8000 Merge branch '4.4' into 5.3 · symfony/symfony@16f8703 · GitHub
[go: up one dir, main page]

Skip to content

Commit 16f8703

Browse files
committed
Merge branch '4.4' into 5.3
* 4.4: [Mime] Fix encoding filenames in multipart/form-data [Validator] Improve French translation [Translations] Add missing translations for Galician (gl) [DependencyInjection] fix linting callable classes restore the overriden locale on tearDown - avoid interfering with any configured value [DependencyInjection] Cast tag value to string
2 parents a7e4494 + 0558be7 commit 16f8703

File tree

11 files changed

+74
-7
lines changed

11 files changed

+74
-7
lines changed

src/Symfony/Component/DependencyInjection/Compiler/AbstractRecursivePass.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ protected function getReflectionMethod(Definition $definition, string $method)
198198
}
199199

200200
if (!$r->hasMethod($method)) {
201+
if ($r->hasMethod('__call') && ($r = $r->getMethod('__call')) && $r->isPublic()) {
202+
return new \ReflectionMethod(static function (...$arguments) {}, '__invoke');
203+
}
204+
201205
throw new RuntimeException(sprintf('Invalid service "%s": method "%s()" does not exist.', $this->currentId, $class !== $this->currentId ? $class.'::'.$method : $method));
202206
}
203207

src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ private function addService(Definition $definition, ?string $id, \DOMElement $pa
143143
$tag->appendChild($this->document->createTextNode($name));
144144
}
145145
foreach ($attributes as $key => $value) {
146-
$tag->setAttribute($key, $value);
146+
$tag->setAttribute($key, $value ?? '');
147147
}
148148
$service->appendChild($tag);
149149
}

src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckTypeDeclarationsPassTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,4 +985,22 @@ public function testIntersectionTypeFailsWithReference()
985985

986986
(new CheckTypeDeclarationsPass(true))->process($container);
987987
}
988+
989+
public function testCallableClass()
990+
{
991+
$container = new ContainerBuilder();
992+
$definition = $container->register('foo', CallableClass::class);
993+
$definition->addMethodCall('callMethod', [123]);
994+
995+
(new CheckTypeDeclarationsPass())->process($container);
996+
997+
$this->addToAssertionCount(1);
998+
}
999+
}
1000+
1001+
class CallableClass
1002+
{
1003+
public function __call($name, $arguments)
1004+
{
1005+
}
9881006
}

src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
->register('foo', FooClass::class)
1818
->addTag('foo', ['foo' => 'foo'])
1919
->addTag('foo', ['bar' => 'bar', 'baz' => 'baz'])
20+
->addTag('nullable', ['bar' => 'bar', 'baz' => null])
2021
->addTag('foo', ['name' => 'bar', 'baz' => 'baz'])
2122
->setFactory(['Bar\\FooClass', 'getInstance'])
2223
->setArguments(['foo', new Reference('foo.baz'), ['%foo%' => 'foo is %foo%', 'foobar' => '%foo%'], true, new Reference('service_container')])

src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services9.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<tag name="foo" foo="foo"/>
1212
<tag name="foo" bar="bar" baz="baz"/>
1313
<tag name="bar" baz="baz">foo</tag>
14+
<tag name="nullable" bar="bar" baz=""/>
1415
<argument>foo</argument>
1516
<argument type="service" id="foo.baz"/>
1617
<argument type="collection">

src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services9.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ services:
1414
- foo: { foo: foo }
1515
- foo: { bar: bar, baz: baz }
1616
- foo: { name: bar, baz: baz }
17+
- nullable: { bar: bar, baz: ~ }
1718
arguments: [foo, '@foo.baz', { '%foo%': 'foo is %foo%', foobar: '%foo%' }, true, '@service_container']
1819
properties: { foo: bar, moo: '@foo.baz', qux: { '%foo%': 'foo is %foo%', foobar: '%foo%' } }
1920
calls:

src/Symfony/Component/Mime/Header/ParameterizedHeader.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,22 @@ private function createParameter(string $name, string $value): string
123123
$maxValueLength = $this->getMaxLineLength() - \strlen($name.'*N*="";') - 1;
124124
$firstLineOffset = \strlen($this->getCharset()."'".$this->getLanguage()."'");
125125
}
126+
127+
if (\in_array($name, ['name', 'filename'], true) && 'form-data' === $this->getValue() && 'content-disposition' === strtolower($this->getName()) && preg_match('//u', $value)) {
128+
// WHATWG HTML living standard 4.10.21.8 2 specifies:
129+
// For field names and filenames for file fields, the result of the
130+
// encoding in the previous bullet point must be escaped by replacing
131+
// any 0x0A (LF) bytes with the byte sequence `%0A`, 0x0D (CR) with `%0D`
132+
// and 0x22 (") with `%22`.
133+
// The user agent must not perform any other escapes.
134+
$value = str_replace(['"', "\r", "\n"], ['%22', '%0D', '%0A'], $value);
135+
136+
if (\strlen($value) <= $maxValueLength) {
137+
return $name.'="'.$value.'"';
138+
}
139+
140+
$value = $origValue;
141+
}
126142
}
127143

128144
// Encode if we need to
@@ -158,7 +174,7 @@ private function createParameter(string $name, string $value): string
158174
*/
159175
private function getEndOfParameterValue(string $value, bool $encoded = false, bool $firstLine = false): string
160176
{
161-
$forceHttpQuoting = 'content-disposition' === strtolower($this->getName()) && 'form-data' === $this->getValue();
177+
$forceHttpQuoting = 'form-data' === $this->getValue() && 'content-disposition' === strtolower($this->getName());
162178
if ($forceHttpQuoting || !preg_match('/^'.self::TOKEN_REGEX.'$/D', $value)) {
163179
$value = '"'.$value.'"';
164180
}

src/Symfony/Component/Mime/Tests/Header/ParameterizedHeaderTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,20 @@ public function testSpaceInParamResultsInQuotedString()
5858
$this->assertEquals('attachment; filename="my file.txt"', $header->getBodyAsString());
5959
}
6060

61+
public function testFormDataResultsInQuotedString()
62+
{
63+
$header = new ParameterizedHeader('Content-Disposition', 'form-data');
64+
$header->setParameters(['filename' => 'file.txt']);
65+
$this->assertEquals('form-data; filename="file.txt"', $header->getBodyAsString());
66+
}
67+
68+
public function testFormDataUtf8()
69+
{
70+
$header = new ParameterizedHeader('Content-Disposition', 'form-data');
71+
$header->setParameters(['filename' => "déjà%\"\n\r.txt"]);
72+
$this->assertEquals('form-data; filename="déjà%%22%0A%0D.txt"', $header->getBodyAsString());
73+
}
74+
6175
public function testLongParamsAreBrokenIntoMultipleAttributeStrings()
6276
{
6377
/* -- RFC 2231, 3.

src/Symfony/Component/Validator/Resources/translations/validators.fr.xlf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@
192192
</trans-unit>
193193
<trans-unit id="51">
194194
<source>No temporary folder was configured in php.ini.</source>
195-
<target>Aucun répertoire temporaire n'a été configuré dans le php.ini.</target>
195+
<target>Aucun répertoire temporaire n'a été configuré dans le php.ini, ou le répertoire configuré n'existe pas.</target>
196196
</trans-unit>
197197
<trans-unit id="52">
198198
<source>Cannot write temporary file to disk.</source>

src/Symfony/Component/Validator/Resources/translations/validators.gl.xlf

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@
192192
</trans-unit>
193193
<trans-unit id="51">
194194
<source>No temporary folder was configured in php.ini.</source>
195-
<target>Ningunha carpeta temporal foi configurada en php.ini.</target>
195+
<target>Ningunha carpeta temporal foi configurada en php.ini, ou a carpeta non existe.</target>
196196
</trans-unit>
197197
<trans-unit id="52">
198198
<source>Cannot write temporary file to disk.</source>
@@ -364,7 +364,7 @@
364364
</trans-unit>
365365
<trans-unit id="94">
366366
<source>This value should be between {{ min }} and {{ max }}.</source>
367-
<target>Este valor debe estar comprendido entre {{min}} e {{max}}.</target>
367+
<target>Este valor debe estar comprendido entre {{ min }} e {{ max }}.</target>
368368
</trans-unit>
369369
<trans-unit id="95">
370370
<source>This value is not a valid hostname.</source>
@@ -394,6 +394,14 @@
394394
<source>This value is not a valid CSS color.</source>
395395
<target>Este valor non é unha cor CSS válida.</target>
396396
</trans-unit>
397+
<trans-unit id="102">
398+
<source>This value is not a valid CIDR notation.</source>
399+
<target>Este valor non ten unha notación CIDR válida.</target>
400+
</trans-unit>
401+
<trans-unit id="103">
402+
<source>The value of the netmask should be between {{ min }} and {{ max }}.</source>
403+
<target>O valor da máscara de rede debería estar entre {{ min }} e {{ max }}.</target>
404+
</trans-unit>
397405
</body>
398406
</file>
399407
</xliff>

src/Symfony/Component/Validator/Test/ConstraintValidatorTestCase.php

Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ abstract class ConstraintValidatorTestCase extends TestCase
5858
protected $propertyPath;
5959
protected $constraint;
6060
protected $defaultTimezone;
61+
private $defaultLocale;
6162
private $expectedViolations;
6263
private $call;
6364

@@ -78,17 +79,20 @@ protected function setUp(): void
7879
$this->validator = $this->createValidator();
7980
$this->validator->initialize($this->context);
8081

82+
$this->defaultLocale = \Locale::getDefault();
83+
\Locale::setDefault('en');
84+
8185
$this->expectedViolations = [];
8286
$this->call = 0;
8387

84-
\Locale::setDefault('en');
85-
8688
$this->setDefaultTimezone('UTC');
8789
}
8890

8991
protected function tearDown(): void
9092
{
9193
$this->restoreDefaultTimezone();
94+
95+
\Locale::setDefault($this->defaultLocale);
9296
}
9397

9498
protected function setDefaultTimezone(?string $defaultTimezone)

0 commit comments

Comments
 (0)
0