Skip to content

Commit

Permalink
Merge branch '4.4' into 5.3
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
derrabus committed Dec 21, 2021
2 parents a7e4494 + 0558be7 commit 16f8703
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 7 deletions.
Expand Up @@ -198,6 +198,10 @@ protected function getReflectionMethod(Definition $definition, string $method)
}

if (!$r->hasMethod($method)) {
if ($r->hasMethod('__call') && ($r = $r->getMethod('__call')) && $r->isPublic()) {
return new \ReflectionMethod(static function (...$arguments) {}, '__invoke');
}

throw new RuntimeException(sprintf('Invalid service "%s": method "%s()" does not exist.', $this->currentId, $class !== $this->currentId ? $class.'::'.$method : $method));
}

Expand Down
Expand Up @@ -143,7 +143,7 @@ private function addService(Definition $definition, ?string $id, \DOMElement $pa
$tag->appendChild($this->document->createTextNode($name));
}
foreach ($attributes as $key => $value) {
$tag->setAttribute($key, $value);
$tag->setAttribute($key, $value ?? '');
}
$service->appendChild($tag);
}
Expand Down
Expand Up @@ -985,4 +985,22 @@ public function testIntersectionTypeFailsWithReference()

(new CheckTypeDeclarationsPass(true))->process($container);
}

public function testCallableClass()
{
$container = new ContainerBuilder();
$definition = $container->register('foo', CallableClass::class);
$definition->addMethodCall('callMethod', [123]);

(new CheckTypeDeclarationsPass())->process($container);

$this->addToAssertionCount(1);
}
}

class CallableClass
{
public function __call($name, $arguments)
{
}
}
Expand Up @@ -17,6 +17,7 @@
->register('foo', FooClass::class)
->addTag('foo', ['foo' => 'foo'])
->addTag('foo', ['bar' => 'bar', 'baz' => 'baz'])
->addTag('nullable', ['bar' => 'bar', 'baz' => null])
->addTag('foo', ['name' => 'bar', 'baz' => 'baz'])
->setFactory(['Bar\\FooClass', 'getInstance'])
->setArguments(['foo', new Reference('foo.baz'), ['%foo%' => 'foo is %foo%', 'foobar' => '%foo%'], true, new Reference('service_container')])
Expand Down
Expand Up @@ -11,6 +11,7 @@
<tag name="foo" foo="foo"/>
<tag name="foo" bar="bar" baz="baz"/>
<tag name="bar" baz="baz">foo</tag>
<tag name="nullable" bar="bar" baz=""/>
<argument>foo</argument>
<argument type="service" id="foo.baz"/>
<argument type="collection">
Expand Down
Expand Up @@ -14,6 +14,7 @@ services:
- foo: { foo: foo }
- foo: { bar: bar, baz: baz }
- foo: { name: bar, baz: baz }
- nullable: { bar: bar, baz: ~ }
arguments: [foo, '@foo.baz', { '%foo%': 'foo is %foo%', foobar: '%foo%' }, true, '@service_container']
properties: { foo: bar, moo: '@foo.baz', qux: { '%foo%': 'foo is %foo%', foobar: '%foo%' } }
calls:
Expand Down
18 changes: 17 additions & 1 deletion src/Symfony/Component/Mime/Header/ParameterizedHeader.php
Expand Up @@ -123,6 +123,22 @@ private function createParameter(string $name, string $value): string
$maxValueLength = $this->getMaxLineLength() - \strlen($name.'*N*="";') - 1;
$firstLineOffset = \strlen($this->getCharset()."'".$this->getLanguage()."'");
}

if (\in_array($name, ['name', 'filename'], true) && 'form-data' === $this->getValue() && 'content-disposition' === strtolower($this->getName()) && preg_match('//u', $value)) {
// WHATWG HTML living standard 4.10.21.8 2 specifies:
// For field names and filenames for file fields, the result of the
// encoding in the previous bullet point must be escaped by replacing
// any 0x0A (LF) bytes with the byte sequence `%0A`, 0x0D (CR) with `%0D`
// and 0x22 (") with `%22`.
// The user agent must not perform any other escapes.
$value = str_replace(['"', "\r", "\n"], ['%22', '%0D', '%0A'], $value);

if (\strlen($value) <= $maxValueLength) {
return $name.'="'.$value.'"';
}

$value = $origValue;
}
}

// Encode if we need to
Expand Down Expand Up @@ -158,7 +174,7 @@ private function createParameter(string $name, string $value): string
*/
private function getEndOfParameterValue(string $value, bool $encoded = false, bool $firstLine = false): string
{
$forceHttpQuoting = 'content-disposition' === strtolower($this->getName()) && 'form-data' === $this->getValue();
$forceHttpQuoting = 'form-data' === $this->getValue() && 'content-disposition' === strtolower($this->getName());
if ($forceHttpQuoting || !preg_match('/^'.self::TOKEN_REGEX.'$/D', $value)) {
$value = '"'.$value.'"';
}
Expand Down
Expand Up @@ -58,6 +58,20 @@ public function testSpaceInParamResultsInQuotedString()
$this->assertEquals('attachment; filename="my file.txt"', $header->getBodyAsString());
}

public function testFormDataResultsInQuotedString()
{
$header = new ParameterizedHeader('Content-Disposition', 'form-data');
$header->setParameters(['filename' => 'file.txt']);
$this->assertEquals('form-data; filename="file.txt"', $header->getBodyAsString());
}

public function testFormDataUtf8()
{
$header = new ParameterizedHeader('Content-Disposition', 'form-data');
$header->setParameters(['filename' => "déjà%\"\n\r.txt"]);
$this->assertEquals('form-data; filename="déjà%%22%0A%0D.txt"', $header->getBodyAsString());
}

public function testLongParamsAreBrokenIntoMultipleAttributeStrings()
{
/* -- RFC 2231, 3.
Expand Down
Expand Up @@ -192,7 +192,7 @@
</trans-unit>
<trans-unit id="51">
<source>No temporary folder was configured in php.ini.</source>
<target>Aucun répertoire temporaire n'a été configuré dans le php.ini.</target>
<target>Aucun répertoire temporaire n'a été configuré dans le php.ini, ou le répertoire configuré n'existe pas.</target>
</trans-unit>
<trans-unit id="52">
<source>Cannot write temporary file to disk.</source>
Expand Down
Expand Up @@ -192,7 +192,7 @@
</trans-unit>
<trans-unit id="51">
<source>No temporary folder was configured in php.ini.</source>
<target>Ningunha carpeta temporal foi configurada en php.ini.</target>
<target>Ningunha carpeta temporal foi configurada en php.ini, ou a carpeta non existe.</target>
</trans-unit>
<trans-unit id="52">
<source>Cannot write temporary file to disk.</source>
Expand Down Expand Up @@ -364,7 +364,7 @@
</trans-unit>
<trans-unit id="94">
<source>This value should be between {{ min }} and {{ max }}.</source>
<target>Este valor debe estar comprendido entre {{min}} e {{max}}.</target>
<target>Este valor debe estar comprendido entre {{ min }} e {{ max }}.</target>
</trans-unit>
<trans-unit id="95">
<source>This value is not a valid hostname.</source>
Expand Down Expand Up @@ -394,6 +394,14 @@
<source>This value is not a valid CSS color.</source>
<target>Este valor non é unha cor CSS válida.</target>
</trans-unit>
<trans-unit id="102">
<source>This value is not a valid CIDR notation.</source>
<target>Este valor non ten unha notación CIDR válida.</target>
</trans-unit>
<trans-unit id="103">
<source>The value of the netmask should be between {{ min }} and {{ max }}.</source>
<target>O valor da máscara de rede debería estar entre {{ min }} e {{ max }}.</target>
</trans-unit>
</body>
</file>
</xliff>
Expand Up @@ -58,6 +58,7 @@ abstract class ConstraintValidatorTestCase extends TestCase
protected $propertyPath;
protected $constraint;
protected $defaultTimezone;
private $defaultLocale;
private $expectedViolations;
private $call;

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

$this->defaultLocale = \Locale::getDefault();
\Locale::setDefault('en');

$this->expectedViolations = [];
$this->call = 0;

\Locale::setDefault('en');

$this->setDefaultTimezone('UTC');
}

protected function tearDown(): void
{
$this->restoreDefaultTimezone();

\Locale::setDefault($this->defaultLocale);
}

protected function setDefaultTimezone(?string $defaultTimezone)
Expand Down

0 comments on commit 16f8703

Please sign in to comment.