Skip to content

Commit

Permalink
Merge branch '3.4' into 4.4
Browse files Browse the repository at this point in the history
* 3.4:
  [Yaml] fix dumping strings containing CRs
  [DI] Fix XmlFileLoader bad error message
  Tweak message
  improve PlaintextPasswordEncoder docBlock summary
  [Validator] Add two missing translations for the Arabic (ar) locale
  Use some PHP 5.4 constants unconditionally
  Revert "bug #28179 [DomCrawler] Skip disabled fields processing in Form"
  Add Spanish translation
  Fix typo
  [Validator] add Japanese translation
  Fix typo
  Add Polish translation
  [SecurityBundle] Minor fixes in configuration tree builder
  bumped Symfony version to 3.4.39
  updated VERSION for 3.4.38
  update CONTRIBUTORS for 3.4.38
  updated CHANGELOG for 3.4.38
  • Loading branch information
nicolas-grekas committed Mar 11, 2020
2 parents 14b825b + bdd66aa commit d0b7445
Show file tree
Hide file tree
Showing 18 changed files with 228 additions and 88 deletions.
178 changes: 114 additions & 64 deletions CONTRIBUTORS.md

Large diffs are not rendered by default.

Expand Up @@ -248,9 +248,9 @@ public function humanize($text)
public function formEncodeCurrency($text, $widget = '')
{
if ('UTF-8' === $charset = $this->getCharset()) {
$text = htmlspecialchars($text, ENT_QUOTES | (\defined('ENT_SUBSTITUTE') ? ENT_SUBSTITUTE : 0), 'UTF-8');
$text = htmlspecialchars($text, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
} else {
$text = htmlentities($text, ENT_QUOTES | (\defined('ENT_SUBSTITUTE') ? ENT_SUBSTITUTE : 0), 'UTF-8');
$text = htmlentities($text, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
$text = iconv('UTF-8', $charset, $text);
$widget = iconv('UTF-8', $charset, $widget);
}
Expand Down
Expand Up @@ -141,7 +141,7 @@ public function addConfiguration(NodeDefinition $node)
->end()
->prototype('scalar')->end()
->end()
->scalarNode('catch_exceptions')->defaultTrue()->end()
->booleanNode('catch_exceptions')->defaultTrue()->end()
;

foreach ($this->options as $name => $value) {
Expand All @@ -151,6 +151,8 @@ public function addConfiguration(NodeDefinition $node)
$builder->enumNode($name)->values([null, Cookie::SAMESITE_LAX, Cookie::SAMESITE_STRICT, Cookie::SAMESITE_NONE])->defaultValue($value);
} elseif (\is_bool($value)) {
$builder->booleanNode($name)->defaultValue($value);
} elseif (\is_int($value)) {
$builder->integerNode($name)->defaultValue($value);
} else {
$builder->scalarNode($name)->defaultValue($value);
}
Expand Down
Expand Up @@ -48,11 +48,12 @@ public function getKey()
public function addConfiguration(NodeDefinition $node)
{
$node
->fixXmlConfig('default_role')
->children()
->scalarNode('service')->isRequired()->cannotBeEmpty()->defaultValue('ldap')->end()
->scalarNode('base_dn')->isRequired()->cannotBeEmpty()->end()
->scalarNode('search_dn')->end()
->scalarNode('search_password')->end()
->scalarNode('search_dn')->defaultNull()->end()
->scalarNode('search_password')->defaultNull()->end()
->arrayNode('extra_fields')
->prototype('scalar')->end()
->end()
Expand Down
Empty file.
29 changes: 27 additions & 2 deletions src/Symfony/Component/Config/Tests/Util/XmlUtilsTest.php
Expand Up @@ -20,6 +20,31 @@ public function testLoadFile()
{
$fixtures = __DIR__.'/../Fixtures/Util/';

try {
XmlUtils::loadFile($fixtures);
$this->fail();
} catch (\InvalidArgumentException $e) {
$this->assertStringContainsString('is not a file', $e->getMessage());
}

try {
XmlUtils::loadFile($fixtures.'non_existing.xml');
$this->fail();
} catch (\InvalidArgumentException $e) {
$this->assertStringContainsString('is not a file', $e->getMessage());
}

try {
if ('\\' === \DIRECTORY_SEPARATOR) {
$this->markTestSkipped('chmod is not supported on Windows');
}
chmod($fixtures.'not_readable.xml', 000);
XmlUtils::loadFile($fixtures.'not_readable.xml');
$this->fail();
} catch (\InvalidArgumentException $e) {
$this->assertStringContainsString('is not readable', $e->getMessage());
}

try {
XmlUtils::loadFile($fixtures.'invalid.xml');
$this->fail();
Expand Down Expand Up @@ -165,7 +190,7 @@ public function testLoadEmptyXmlFile()
$file = __DIR__.'/../Fixtures/foo.xml';

$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage(sprintf('File %s does not contain valid XML, it is empty.', $file));
$this->expectExceptionMessage(sprintf('File "%s" does not contain valid XML, it is empty.', $file));

XmlUtils::loadFile($file);
}
Expand All @@ -186,7 +211,7 @@ public function testLoadWrongEmptyXMLWithErrorHandler()
XmlUtils::loadFile($file);
$this->fail('An exception should have been raised');
} catch (\InvalidArgumentException $e) {
$this->assertEquals(sprintf('File %s does not contain valid XML, it is empty.', $file), $e->getMessage());
$this->assertEquals(sprintf('File "%s" does not contain valid XML, it is empty.', $file), $e->getMessage());
}
} finally {
restore_error_handler();
Expand Down
11 changes: 10 additions & 1 deletion src/Symfony/Component/Config/Util/XmlUtils.php
Expand Up @@ -122,9 +122,18 @@ public static function parse($content, $schemaOrCallable = null)
*/
public static function loadFile($file, $schemaOrCallable = null)
{
if (!is_file($file)) {
throw new \InvalidArgumentException(sprintf('Resource "%s" is not a file.', $file));
}

if (!is_readable($file)) {
throw new \InvalidArgumentException(sprintf('File "%s" is not readable.', $file));
}

$content = @file_get_contents($file);

if ('' === trim($content)) {
throw new \InvalidArgumentException(sprintf('File %s does not contain valid XML, it is empty.', $file));
throw new \InvalidArgumentException(sprintf('File "%s" does not contain valid XML, it is empty.', $file));
}

try {
Expand Down
10 changes: 9 additions & 1 deletion src/Symfony/Component/DomCrawler/Form.php
Expand Up @@ -89,6 +89,10 @@ public function getValues()
{
$values = [];
foreach ($this->fields->all() as $name => $field) {
if ($field->isDisabled()) {
continue;
}

if (!$field instanceof Field\FileFormField && $field->hasValue()) {
$values[$name] = $field->getValue();
}
Expand All @@ -111,6 +115,10 @@ public function getFiles()
$files = [];

foreach ($this->fields->all() as $name => $field) {
if ($field->isDisabled()) {
continue;
}

if ($field instanceof Field\FileFormField) {
$files[$name] = $field->getValue();
}
Expand Down Expand Up @@ -465,7 +473,7 @@ private function initialize()

private function addField(\DOMElement $node)
{
if (!$node->hasAttribute('name') || !$node->getAttribute('name') || $node->hasAttribute('disabled')) {
if (!$node->hasAttribute('name') || !$node->getAttribute('name')) {
return;
}

Expand Down
16 changes: 8 additions & 8 deletions src/Symfony/Component/DomCrawler/Tests/FormTest.php
Expand Up @@ -159,12 +159,12 @@ public function testConstructorHandlesFormValues()
public function testMultiValuedFields()
{
$form = $this->createForm('<form>
<input type="text" name="foo[4]" value="foo" />
<input type="text" name="foo" value="foo" />
<input type="text" name="foo[2]" value="foo" />
<input type="text" name="foo[]" value="foo" />
<input type="text" name="bar[foo][]" value="foo" />
<input type="text" name="bar[foo][foobar]" value="foo" />
<input type="text" name="foo[4]" value="foo" disabled="disabled" />
<input type="text" name="foo" value="foo" disabled="disabled" />
<input type="text" name="foo[2]" value="foo" disabled="disabled" />
<input type="text" name="foo[]" value="foo" disabled="disabled" />
<input type="text" name="bar[foo][]" value="foo" disabled="disabled" />
<input type="text" name="bar[foo][foobar]" value="foo" disabled="disabled" />
<input type="submit" />
</form>
');
Expand Down Expand Up @@ -227,10 +227,10 @@ public function provideInitializeValues()
[],
],
[
'skips disabled input fields',
'takes into account disabled input fields',
'<input type="text" name="foo" value="foo" disabled="disabled" />
<input type="submit" />',
[],
['foo' => ['InputFormField', 'foo']],
],
[
'appends the submitted button value',
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Form/FormRenderer.php
Expand Up @@ -293,9 +293,9 @@ public function humanize($text)
public function encodeCurrency(Environment $environment, string $text, string $widget = ''): string
{
if ('UTF-8' === $charset = $environment->getCharset()) {
$text = htmlspecialchars($text, ENT_QUOTES | (\defined('ENT_SUBSTITUTE') ? ENT_SUBSTITUTE : 0), 'UTF-8');
$text = htmlspecialchars($text, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
} else {
$text = htmlentities($text, ENT_QUOTES | (\defined('ENT_SUBSTITUTE') ? ENT_SUBSTITUTE : 0), 'UTF-8');
$text = htmlentities($text, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
$text = iconv('UTF-8', $charset, $text);
$widget = iconv('UTF-8', $charset, $widget);
}
Expand Down
Expand Up @@ -14,7 +14,9 @@
use Symfony\Component\Security\Core\Exception\BadCredentialsException;

/**
* PlaintextPasswordEncoder does not do any encoding.
* PlaintextPasswordEncoder does not do any encoding but is useful in testing environments.
*
* As this encoder is not cryptographically secure, usage of it in production environments is discouraged.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
Expand Down
Expand Up @@ -366,6 +366,14 @@
<source>This value should be between {{ min }} and {{ max }}.</source>
<target>يجب أن تكون هذه القيمة بين {{ min }} و {{ max }}.</target>
</trans-unit>
<trans-unit id="95">
<source>This value is not a valid hostname.</source>
<target>هذه القيمة ليست اسم مضيف صالح.</target>
</trans-unit>
<trans-unit id="96">
<source>The number of elements in this collection should be a multiple of {{ compared_value }}.</source>
<target>يجب أن يكون عدد العناصر في هذه المجموعة مضاعف {{ compared_value }}.</target>
</trans-unit>
</body>
</file>
</xliff>
Expand Up @@ -364,7 +364,15 @@
</trans-unit>
<trans-unit id="94">
<source>This value should be between {{ min }} and {{ max }}.</source>
<target>Este valor debe estar entre {{ min }} y {{ max }}.</target>
<target>Este valor debería estar entre {{ min }} y {{ max }}.</target>
</trans-unit>
<trans-unit id="95">
<source>This value is not a valid hostname.</source>
<target>Este valor no es un nombre de host válido.</target>
</trans-unit>
<trans-unit id="96">
<source>The number of elements in this collection should be a multiple of {{ compared_value }}.</source>
<target>El número de elementos en esta colección debería ser múltiplo de {{ compared_value }}.</target>
</trans-unit>
</body>
</file>
Expand Down
Expand Up @@ -366,6 +366,14 @@
<source>This value should be between {{ min }} and {{ max }}.</source>
<target>{{ min }}以上{{ max }}以下でなければなりません。</target>
</trans-unit>
<trans-unit id="95">
<source>This value is not a valid hostname.</source>
<target>有効なホスト名ではありません。</target>
</trans-unit>
<trans-unit id="96">
<source>The number of elements in this collection should be a multiple of {{ compared_value }}.</source>
<target>要素の数は{{ compared_value }}の倍数でなければなりません。</target>
</trans-unit>
</body>
</file>
</xliff>
Expand Up @@ -370,6 +370,10 @@
<source>This value is not a valid hostname.</source>
<target>Ta wartość nie jest prawidłową nazwą hosta.</target>
</trans-unit>
<trans-unit id="96">
<source>The number of elements in this collection should be a multiple of {{ compared_value }}.</source>
<target>Liczba elementów w tym zbiorze powinna być wielokrotnością {{ compared_value }}.</target>
</trans-unit>
</body>
</file>
</xliff>
Expand Up @@ -372,7 +372,7 @@
</trans-unit>
<trans-unit id="96">
<source>The number of elements in this collection should be a multiple of {{ compared_value }}.</source>
<target>Số lượng các phần tử trong bộ sưu tập này nên là bội số của {{compared_value}}.</target>
<target>Số lượng các phần tử trong bộ sưu tập này nên là bội số của {{ compared_value }}.</target>
</trans-unit>
</body>
</file>
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Yaml/Dumper.php
Expand Up @@ -64,7 +64,7 @@ public function dump($input, int $inline = 0, int $indent = 0, int $flags = 0):
$dumpAsMap = Inline::isHash($input);

foreach ($input as $key => $value) {
if ($inline >= 1 && Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK & $flags && \is_string($value) && false !== strpos($value, "\n") && false === strpos($value, "\r\n")) {
if ($inline >= 1 && Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK & $flags && \is_string($value) && false !== strpos($value, "\n") && false === strpos($value, "\r")) {
// If the first line starts with a space character, the spec requires a blockIndicationIndicator
// http://www.yaml.org/spec/1.2/spec.html#id2793979
$blockIndentationIndicator = (' ' === substr($value, 0, 1)) ? (string) $this->indentation : '';
Expand Down
17 changes: 16 additions & 1 deletion src/Symfony/Component/Yaml/Tests/DumperTest.php
Expand Up @@ -547,11 +547,26 @@ public function testDumpMultiLineStringAsScalarBlockWhenFirstLineHasLeadingSpace
$this->assertSame(file_get_contents(__DIR__.'/Fixtures/multiple_lines_as_literal_block_leading_space_in_first_line.yml'), $this->dumper->dump($data, 2, 0, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK));
}

public function testCarriageReturnIsMaintainedWhenDumpingAsMultiLineLiteralBlock()
public function testCarriageReturnFollowedByNewlineIsMaintainedWhenDumpingAsMultiLineLiteralBlock()
{
$this->assertSame("- \"a\\r\\nb\\nc\"\n", $this->dumper->dump(["a\r\nb\nc"], 2, 0, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK));
}

public function testCarriageReturnNotFollowedByNewlineIsPreservedWhenDumpingAsMultiLineLiteralBlock()
{
$expected = <<<'YAML'
parent:
foo: "bar\n\rbaz: qux"
YAML;

$this->assertSame($expected, $this->dumper->dump([
'parent' => [
'foo' => "bar\n\rbaz: qux",
],
], 4, 0, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK));
}

public function testZeroIndentationThrowsException()
{
$this->expectException('InvalidArgumentException');
Expand Down

0 comments on commit d0b7445

Please sign in to comment.