From fc6cf3d3c6903597ad4576e0123cd1f1a8155f59 Mon Sep 17 00:00:00 2001 From: Thomas Calvet Date: Mon, 20 Apr 2020 12:25:20 +0200 Subject: [PATCH 01/11] [DX] Show the ParseException message in YAML file loaders --- .../Component/DependencyInjection/Loader/YamlFileLoader.php | 2 +- src/Symfony/Component/Routing/Loader/YamlFileLoader.php | 2 +- src/Symfony/Component/Translation/Loader/YamlFileLoader.php | 2 +- .../Component/Validator/Mapping/Loader/YamlFileLoader.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php index bc0c55e94d..ae970dbdf1 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php @@ -660,7 +660,7 @@ class YamlFileLoader extends FileLoader try { $configuration = $this->yamlParser->parseFile($file, Yaml::PARSE_CONSTANT | Yaml::PARSE_CUSTOM_TAGS); } catch (ParseException $e) { - throw new InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML: '.$e->getMessage(), $file), 0, $e); + throw new InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML', $file).': '.$e->getMessage(), 0, $e); } finally { restore_error_handler(); } diff --git a/src/Symfony/Component/Routing/Loader/YamlFileLoader.php b/src/Symfony/Component/Routing/Loader/YamlFileLoader.php index 568827695b..57f1270d9f 100644 --- a/src/Symfony/Component/Routing/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/Routing/Loader/YamlFileLoader.php @@ -66,7 +66,7 @@ class YamlFileLoader extends FileLoader try { $parsedConfig = $this->yamlParser->parseFile($path); } catch (ParseException $e) { - throw new \InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML.', $path), 0, $e); + throw new \InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML', $path).': '.$e->getMessage(), 0, $e); } finally { restore_error_handler(); } diff --git a/src/Symfony/Component/Translation/Loader/YamlFileLoader.php b/src/Symfony/Component/Translation/Loader/YamlFileLoader.php index 41700df24b..0c25787dc7 100644 --- a/src/Symfony/Component/Translation/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/Translation/Loader/YamlFileLoader.php @@ -47,7 +47,7 @@ class YamlFileLoader extends FileLoader try { $messages = $this->yamlParser->parseFile($resource); } catch (ParseException $e) { - throw new InvalidResourceException(sprintf('Error parsing YAML, invalid file "%s".', $resource), 0, $e); + throw new InvalidResourceException(sprintf('The file "%s" does not contain valid YAML', $resource).': '.$e->getMessage(), 0, $e); } finally { restore_error_handler(); } diff --git a/src/Symfony/Component/Validator/Mapping/Loader/YamlFileLoader.php b/src/Symfony/Component/Validator/Mapping/Loader/YamlFileLoader.php index 0f6166674d..519c2ed36d 100644 --- a/src/Symfony/Component/Validator/Mapping/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/Validator/Mapping/Loader/YamlFileLoader.php @@ -124,7 +124,7 @@ class YamlFileLoader extends FileLoader try { $classes = $this->yamlParser->parseFile($path, Yaml::PARSE_CONSTANT); } catch (ParseException $e) { - throw new \InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML.', $path), 0, $e); + throw new \InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML', $path).': '.$e->getMessage(), 0, $e); } finally { restore_error_handler(); } From 856ba8c98fd6f04f451bff2af6255322c1b8e139 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 29 Apr 2020 17:41:38 +0200 Subject: [PATCH 02/11] [PhpUnitBridge] fix compat with PHP 5.3 --- .../Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php | 2 +- src/Symfony/Bridge/PhpUnit/bin/simple-phpunit | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php b/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php index e260fb8dd6..a7bfd80ede 100644 --- a/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php +++ b/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php @@ -47,7 +47,7 @@ class SymfonyTestsListenerTrait { if (class_exists('PHPUnit_Util_Blacklist')) { \PHPUnit_Util_Blacklist::$blacklistedClassNames[__CLASS__] = 2; - } elseif (method_exists(Blacklist::class, 'addDirectory')) { + } elseif (method_exists('PHPUnit\Util\Blacklist', 'addDirectory')) { (new BlackList())->getBlacklistedDirectories(); Blacklist::addDirectory(\dirname((new \ReflectionClass(__CLASS__))->getFileName(), 2)); } else { diff --git a/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit b/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit index 92d4d6994a..f37967ff0c 100755 --- a/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit +++ b/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit @@ -130,8 +130,8 @@ if (class_exists('PHPUnit_Util_Blacklist')) { PHPUnit_Util_Blacklist::$blacklistedClassNames['SymfonyBlacklistSimplePhpunit'] = 1; } elseif (method_exists('PHPUnit\Util\Blacklist', 'addDirectory')) { (new PHPUnit\Util\BlackList())->getBlacklistedDirectories(); - PHPUnit\Util\Blacklist::addDirectory(\dirname((new \ReflectionClass('SymfonyBlacklistPhpunit'))->getFileName())); - PHPUnit\Util\Blacklist::addDirectory(\dirname((new \ReflectionClass('SymfonyBlacklistSimplePhpunit'))->getFileName())); + PHPUnit\Util\Blacklist::addDirectory(dirname((new ReflectionClass('SymfonyBlacklistPhpunit'))->getFileName())); + PHPUnit\Util\Blacklist::addDirectory(dirname((new ReflectionClass('SymfonyBlacklistSimplePhpunit'))->getFileName())); } else { PHPUnit\Util\Blacklist::$blacklistedClassNames['SymfonyBlacklistPhpunit'] = 1; PHPUnit\Util\Blacklist::$blacklistedClassNames['SymfonyBlacklistSimplePhpunit'] = 1; From 67b744929f1bec03cfd037e2c65f99edace109cd Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Fri, 1 May 2020 17:20:42 +0200 Subject: [PATCH 03/11] Fix annotation --- src/Symfony/Component/Form/Form.php | 2 +- src/Symfony/Component/Form/FormInterface.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Form/Form.php b/src/Symfony/Component/Form/Form.php index e9190b82b8..93b62a9acf 100644 --- a/src/Symfony/Component/Form/Form.php +++ b/src/Symfony/Component/Form/Form.php @@ -932,7 +932,7 @@ class Form implements \IteratorAggregate, FormInterface * * @return FormInterface The child form * - * @throws \OutOfBoundsException if the named child does not exist + * @throws OutOfBoundsException if the named child does not exist */ public function offsetGet($name) { diff --git a/src/Symfony/Component/Form/FormInterface.php b/src/Symfony/Component/Form/FormInterface.php index 5c55bcd795..ba6236dd34 100644 --- a/src/Symfony/Component/Form/FormInterface.php +++ b/src/Symfony/Component/Form/FormInterface.php @@ -62,7 +62,7 @@ interface FormInterface extends \ArrayAccess, \Traversable, \Countable * * @return self * - * @throws \OutOfBoundsException if the named child does not exist + * @throws Exception\OutOfBoundsException if the named child does not exist */ public function get($name); From 281861e788865dcecf66e904adf62bda55e01902 Mon Sep 17 00:00:00 2001 From: Ben Davies Date: Wed, 29 Apr 2020 21:31:19 +0100 Subject: [PATCH 04/11] [Validator] fix lazy property usage. --- .../Validator/Tests/Fixtures/Entity.php | 10 ++++ .../Tests/Validator/AbstractValidatorTest.php | 55 ++++++++++++++----- .../RecursiveContextualValidator.php | 4 ++ 3 files changed, 56 insertions(+), 13 deletions(-) diff --git a/src/Symfony/Component/Validator/Tests/Fixtures/Entity.php b/src/Symfony/Component/Validator/Tests/Fixtures/Entity.php index 16ba8a718e..673e62bae7 100644 --- a/src/Symfony/Component/Validator/Tests/Fixtures/Entity.php +++ b/src/Symfony/Component/Validator/Tests/Fixtures/Entity.php @@ -53,6 +53,11 @@ class Entity extends EntityParent implements EntityInterfaceB $this->internal = $internal; } + public function getFirstName() + { + return $this->firstName; + } + public function getInternal() { return $this->internal.' from getter'; @@ -141,4 +146,9 @@ class Entity extends EntityParent implements EntityInterfaceB { $this->childB = $childB; } + + public function getReference() + { + return $this->reference; + } } diff --git a/src/Symfony/Component/Validator/Tests/Validator/AbstractValidatorTest.php b/src/Symfony/Component/Validator/Tests/Validator/AbstractValidatorTest.php index 07e45f47eb..8482a71a38 100644 --- a/src/Symfony/Component/Validator/Tests/Validator/AbstractValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Validator/AbstractValidatorTest.php @@ -32,6 +32,8 @@ abstract class AbstractValidatorTest extends TestCase const REFERENCE_CLASS = 'Symfony\Component\Validator\Tests\Fixtures\Reference'; + const LAZY_PROPERTY = 'Symfony\Component\Validator\Validator\LazyProperty'; + /** * @var FakeMetadataFactory */ @@ -54,6 +56,7 @@ abstract class AbstractValidatorTest extends TestCase $this->referenceMetadata = new ClassMetadata(self::REFERENCE_CLASS); $this->metadataFactory->addMetadata($this->metadata); $this->metadataFactory->addMetadata($this->referenceMetadata); + $this->metadataFactory->addMetadata(new ClassMetadata(self::LAZY_PROPERTY)); } protected function tearDown() @@ -510,7 +513,10 @@ abstract class AbstractValidatorTest extends TestCase $this->validate($entity); } - public function testArrayReference() + /** + * @dataProvider getConstraintMethods + */ + public function testArrayReference($constraintMethod) { $entity = new Entity(); $entity->reference = ['key' => new Reference()]; @@ -528,7 +534,7 @@ abstract class AbstractValidatorTest extends TestCase $context->addViolation('Message %param%', ['%param%' => 'value']); }; - $this->metadata->addPropertyConstraint('reference', new Valid()); + $this->metadata->$constraintMethod('reference', new Valid()); $this->referenceMetadata->addConstraint(new Callback([ 'callback' => $callback, 'groups' => 'Group', @@ -548,8 +554,10 @@ abstract class AbstractValidatorTest extends TestCase $this->assertNull($violations[0]->getCode()); } - // https://github.com/symfony/symfony/issues/6246 - public function testRecursiveArrayReference() + /** + * @dataProvider getConstraintMethods + */ + public function testRecursiveArrayReference($constraintMethod) { $entity = new Entity(); $entity->reference = [2 => ['key' => new Reference()]]; @@ -567,7 +575,7 @@ abstract class AbstractValidatorTest extends TestCase $context->addViolation('Message %param%', ['%param%' => 'value']); }; - $this->metadata->addPropertyConstraint('reference', new Valid()); + $this->metadata->$constraintMethod('reference', new Valid()); $this->referenceMetadata->addConstraint(new Callback([ 'callback' => $callback, 'groups' => 'Group', @@ -611,7 +619,10 @@ abstract class AbstractValidatorTest extends TestCase $this->assertCount(0, $violations); } - public function testArrayTraversalCannotBeDisabled() + /** + * @dataProvider getConstraintMethods + */ + public function testArrayTraversalCannotBeDisabled($constraintMethod) { $entity = new Entity(); $entity->reference = ['key' => new Reference()]; @@ -620,7 +631,7 @@ abstract class AbstractValidatorTest extends TestCase $context->addViolation('Message %param%', ['%param%' => 'value']); }; - $this->metadata->addPropertyConstraint('reference', new Valid([ + $this->metadata->$constraintMethod('reference', new Valid([ 'traverse' => false, ])); $this->referenceMetadata->addConstraint(new Callback($callback)); @@ -631,7 +642,10 @@ abstract class AbstractValidatorTest extends TestCase $this->assertCount(1, $violations); } - public function testRecursiveArrayTraversalCannotBeDisabled() + /** + * @dataProvider getConstraintMethods + */ + public function testRecursiveArrayTraversalCannotBeDisabled($constraintMethod) { $entity = new Entity(); $entity->reference = [2 => ['key' => new Reference()]]; @@ -640,9 +654,10 @@ abstract class AbstractValidatorTest extends TestCase $context->addViolation('Message %param%', ['%param%' => 'value']); }; - $this->metadata->addPropertyConstraint('reference', new Valid([ + $this->metadata->$constraintMethod('reference', new Valid([ 'traverse' => false, ])); + $this->referenceMetadata->addConstraint(new Callback($callback)); $violations = $this->validate($entity); @@ -651,12 +666,15 @@ abstract class AbstractValidatorTest extends TestCase $this->assertCount(1, $violations); } - public function testIgnoreScalarsDuringArrayTraversal() + /** + * @dataProvider getConstraintMethods + */ + public function testIgnoreScalarsDuringArrayTraversal($constraintMethod) { $entity = new Entity(); $entity->reference = ['string', 1234]; - $this->metadata->addPropertyConstraint('reference', new Valid()); + $this->metadata->$constraintMethod('reference', new Valid()); $violations = $this->validate($entity); @@ -664,12 +682,15 @@ abstract class AbstractValidatorTest extends TestCase $this->assertCount(0, $violations); } - public function testIgnoreNullDuringArrayTraversal() + /** + * @dataProvider getConstraintMethods + */ + public function testIgnoreNullDuringArrayTraversal($constraintMethod) { $entity = new Entity(); $entity->reference = [null]; - $this->metadata->addPropertyConstraint('reference', new Valid()); + $this->metadata->$constraintMethod('reference', new Valid()); $violations = $this->validate($entity); @@ -1218,6 +1239,14 @@ abstract class AbstractValidatorTest extends TestCase } } + public function getConstraintMethods() + { + return [ + ['addPropertyConstraint'], + ['addGetterConstraint'], + ]; + } + public function getTestReplaceDefaultGroup() { return [ diff --git a/src/Symfony/Component/Validator/Validator/RecursiveContextualValidator.php b/src/Symfony/Component/Validator/Validator/RecursiveContextualValidator.php index 38bd945a6a..a204cd91f6 100644 --- a/src/Symfony/Component/Validator/Validator/RecursiveContextualValidator.php +++ b/src/Symfony/Component/Validator/Validator/RecursiveContextualValidator.php @@ -677,6 +677,10 @@ class RecursiveContextualValidator implements ContextualValidatorInterface // See validateClassNode() $cascadedGroups = null !== $cascadedGroups && \count($cascadedGroups) > 0 ? $cascadedGroups : $groups; + if ($value instanceof LazyProperty) { + $value = $value->getPropertyValue(); + } + if (\is_array($value)) { // Arrays are always traversed, independent of the specified // traversal strategy From 0da177a224440462e807f3a9f3e13fe305ad46b9 Mon Sep 17 00:00:00 2001 From: Marko Kaznovac Date: Sun, 3 May 2020 00:06:24 +0200 Subject: [PATCH 05/11] fix sr_Latn translation *negative* translated as positive --- .../Validator/Resources/translations/validators.sr_Latn.xlf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.sr_Latn.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.sr_Latn.xlf index 20dff43c6d..43d2070ab7 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.sr_Latn.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.sr_Latn.xlf @@ -352,7 +352,7 @@ This value should be either negative or zero. - Ova vrednost bi trebala biti pozitivna ili nula. + Ova vrednost bi trebala biti negativna ili nula. This value is not a valid timezone. From de5d68ef2a6defc2cfd68b5d7a91635bec81451d Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 3 May 2020 21:30:24 +0200 Subject: [PATCH 06/11] Skip validation when email is an empty object --- .../Validator/Constraints/EmailValidator.php | 3 +++ .../Tests/Constraints/EmailValidatorTest.php | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/Symfony/Component/Validator/Constraints/EmailValidator.php b/src/Symfony/Component/Validator/Constraints/EmailValidator.php index d0eaa45402..58b372d988 100644 --- a/src/Symfony/Component/Validator/Constraints/EmailValidator.php +++ b/src/Symfony/Component/Validator/Constraints/EmailValidator.php @@ -51,6 +51,9 @@ class EmailValidator extends ConstraintValidator } $value = (string) $value; + if ('' === $value) { + return; + } if (null === $constraint->strict) { $constraint->strict = $this->isStrict; diff --git a/src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php index 344139a44f..9299c7efad 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php @@ -40,6 +40,13 @@ class EmailValidatorTest extends ConstraintValidatorTestCase $this->assertNoViolation(); } + public function testObjectEmptyStringIsValid() + { + $this->validator->validate(new EmptyEmailObject(), new Email()); + + $this->assertNoViolation(); + } + public function testExpectsStringCompatibleType() { $this->expectException('Symfony\Component\Validator\Exception\UnexpectedTypeException'); @@ -256,3 +263,11 @@ class EmailValidatorTest extends ConstraintValidatorTestCase ]; } } + +class EmptyEmailObject +{ + public function __toString() + { + return ''; + } +} From 065a8cee5ffb4f2d3daf3060bb63cbba55c2291c Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sun, 3 May 2020 23:44:38 +0200 Subject: [PATCH 07/11] [PhpUnitBridge] fix PHP 5.3 compat again --- src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php | 2 ++ src/Symfony/Bridge/PhpUnit/bin/simple-phpunit | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php b/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php index a7bfd80ede..ee9378d140 100644 --- a/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php +++ b/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php @@ -48,8 +48,10 @@ class SymfonyTestsListenerTrait if (class_exists('PHPUnit_Util_Blacklist')) { \PHPUnit_Util_Blacklist::$blacklistedClassNames[__CLASS__] = 2; } elseif (method_exists('PHPUnit\Util\Blacklist', 'addDirectory')) { + eval(" // PHP 5.3 compat (new BlackList())->getBlacklistedDirectories(); Blacklist::addDirectory(\dirname((new \ReflectionClass(__CLASS__))->getFileName(), 2)); + "); } else { Blacklist::$blacklistedClassNames[__CLASS__] = 2; } diff --git a/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit b/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit index f37967ff0c..41445d93ab 100755 --- a/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit +++ b/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit @@ -129,9 +129,11 @@ if (class_exists('PHPUnit_Util_Blacklist')) { PHPUnit_Util_Blacklist::$blacklistedClassNames['SymfonyBlacklistPhpunit'] = 1; PHPUnit_Util_Blacklist::$blacklistedClassNames['SymfonyBlacklistSimplePhpunit'] = 1; } elseif (method_exists('PHPUnit\Util\Blacklist', 'addDirectory')) { + eval(" // PHP 5.3 compat (new PHPUnit\Util\BlackList())->getBlacklistedDirectories(); PHPUnit\Util\Blacklist::addDirectory(dirname((new ReflectionClass('SymfonyBlacklistPhpunit'))->getFileName())); PHPUnit\Util\Blacklist::addDirectory(dirname((new ReflectionClass('SymfonyBlacklistSimplePhpunit'))->getFileName())); + "); } else { PHPUnit\Util\Blacklist::$blacklistedClassNames['SymfonyBlacklistPhpunit'] = 1; PHPUnit\Util\Blacklist::$blacklistedClassNames['SymfonyBlacklistSimplePhpunit'] = 1; From 75405247beed4ac51ef08ade5676d90ed1f2fa96 Mon Sep 17 00:00:00 2001 From: Thomas Calvet Date: Mon, 4 May 2020 09:08:14 +0200 Subject: [PATCH 08/11] [3.4][Inflector] Improve testSingularize() argument name --- .../Component/Inflector/Tests/InflectorTest.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Component/Inflector/Tests/InflectorTest.php b/src/Symfony/Component/Inflector/Tests/InflectorTest.php index ea752b3fac..d43b7ea562 100644 --- a/src/Symfony/Component/Inflector/Tests/InflectorTest.php +++ b/src/Symfony/Component/Inflector/Tests/InflectorTest.php @@ -160,15 +160,15 @@ class InflectorTest extends TestCase /** * @dataProvider singularizeProvider */ - public function testSingularize($plural, $singular) + public function testSingularize($plural, $expectedSingular) { - $single = Inflector::singularize($plural); - if (\is_string($singular) && \is_array($single)) { - $this->fail("--- Expected\n`string`: ".$singular."\n+++ Actual\n`array`: ".implode(', ', $single)); - } elseif (\is_array($singular) && \is_string($single)) { - $this->fail("--- Expected\n`array`: ".implode(', ', $singular)."\n+++ Actual\n`string`: ".$single); + $singular = Inflector::singularize($plural); + if (\is_string($expectedSingular) && \is_array($singular)) { + $this->fail("--- Expected\n`string`: ".$expectedSingular."\n+++ Actual\n`array`: ".implode(', ', $singular)); + } elseif (\is_array($expectedSingular) && \is_string($singular)) { + $this->fail("--- Expected\n`array`: ".implode(', ', $expectedSingular)."\n+++ Actual\n`string`: ".$singular); } - $this->assertEquals($singular, $single); + $this->assertEquals($expectedSingular, $singular); } } From 58bb2c52ac73036262f5b60872edc8a6e8bbe0a9 Mon Sep 17 00:00:00 2001 From: Wouter Diesveld Date: Mon, 4 May 2020 11:46:19 +0200 Subject: [PATCH 09/11] [Yaml] fix parse error when unindented collections contain a comment --- src/Symfony/Component/Yaml/Parser.php | 6 ++++++ .../Component/Yaml/Tests/Fixtures/sfComments.yml | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/Symfony/Component/Yaml/Parser.php b/src/Symfony/Component/Yaml/Parser.php index f1cb6b57aa..39116d8424 100644 --- a/src/Symfony/Component/Yaml/Parser.php +++ b/src/Symfony/Component/Yaml/Parser.php @@ -619,8 +619,14 @@ class Parser } $isItUnindentedCollection = $this->isStringUnIndentedCollectionItem(); + $isItComment = $this->isCurrentLineComment(); while ($this->moveToNextLine()) { + if ($isItComment && !$isItUnindentedCollection) { + $isItUnindentedCollection = $this->isStringUnIndentedCollectionItem(); + $isItComment = $this->isCurrentLineComment(); + } + $indent = $this->getCurrentLineIndentation(); if ($isItUnindentedCollection && !$this->isCurrentLineEmpty() && !$this->isStringUnIndentedCollectionItem() && $newIndent === $indent) { diff --git a/src/Symfony/Component/Yaml/Tests/Fixtures/sfComments.yml b/src/Symfony/Component/Yaml/Tests/Fixtures/sfComments.yml index af3ab38597..4b0c91c9b1 100644 --- a/src/Symfony/Component/Yaml/Tests/Fixtures/sfComments.yml +++ b/src/Symfony/Component/Yaml/Tests/Fixtures/sfComments.yml @@ -74,3 +74,17 @@ yaml: | 'foo #': baz php: | ['foo #' => 'baz'] +--- +test: Comment before first item in unindented collection +brief: > + Comment directly before unindented collection is allowed +yaml: | + collection1: + # comment + - a + - b + collection2: + - a + - b +php: | + ['collection1' => ['a', 'b'], 'collection2' => ['a', 'b']] From d9c47087c97da3fc70a9115c95955d9b9c5248c3 Mon Sep 17 00:00:00 2001 From: Nathan Dench Date: Mon, 4 May 2020 13:38:05 +1000 Subject: [PATCH 10/11] [WebProfiler] Do not add src-elem CSP directives if they do not exist --- .../Csp/ContentSecurityPolicyHandler.php | 21 ++++++++++++------- .../Csp/ContentSecurityPolicyHandlerTest.php | 9 +++++++- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Csp/ContentSecurityPolicyHandler.php b/src/Symfony/Bundle/WebProfilerBundle/Csp/ContentSecurityPolicyHandler.php index e62895fe6d..f75d29aea7 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Csp/ContentSecurityPolicyHandler.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Csp/ContentSecurityPolicyHandler.php @@ -133,12 +133,11 @@ class ContentSecurityPolicyHandler continue; } if (!isset($headers[$header][$type])) { - if (isset($headers[$header]['default-src'])) { - $headers[$header][$type] = $headers[$header]['default-src']; - } else { - // If there is no script-src/style-src and no default-src, no additional rules required. + if (null === $fallback = $this->getDirectiveFallback($directives, $type)) { continue; } + + $headers[$header][$type] = $fallback; } $ruleIsSet = true; if (!\in_array('\'unsafe-inline\'', $headers[$header][$type], true)) { @@ -218,9 +217,7 @@ class ContentSecurityPolicyHandler { if (isset($directivesSet[$type])) { $directives = $directivesSet[$type]; - } elseif (isset($directivesSet['default-src'])) { - $directives = $directivesSet['default-src']; - } else { + } elseif (null === $directives = $this->getDirectiveFallback($directivesSet, $type)) { return false; } @@ -244,6 +241,16 @@ class ContentSecurityPolicyHandler return false; } + private function getDirectiveFallback(array $directiveSet, $type) + { + if (\in_array($type, ['script-src-elem', 'style-src-elem'], true) || !isset($directiveSet['default-src'])) { + // Let the browser fallback on it's own + return null; + } + + return $directiveSet['default-src']; + } + /** * Retrieves the Content-Security-Policy headers (either X-Content-Security-Policy or Content-Security-Policy) from * a response. diff --git a/src/Symfony/Bundle/WebProfilerBundle/Tests/Csp/ContentSecurityPolicyHandlerTest.php b/src/Symfony/Bundle/WebProfilerBundle/Tests/Csp/ContentSecurityPolicyHandlerTest.php index 349db2aaf7..3afe8a95fc 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Tests/Csp/ContentSecurityPolicyHandlerTest.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Tests/Csp/ContentSecurityPolicyHandlerTest.php @@ -131,7 +131,14 @@ class ContentSecurityPolicyHandlerTest extends TestCase ['csp_script_nonce' => $nonce, 'csp_style_nonce' => $nonce], $this->createRequest(), $this->createResponse(['Content-Security-Policy' => 'default-src \'self\' domain.com; script-src \'self\' \'unsafe-inline\'', 'Content-Security-Policy-Report-Only' => 'default-src \'self\' domain-report-only.com; script-src \'self\' \'unsafe-inline\'']), - ['Content-Security-Policy' => 'default-src \'self\' domain.com; script-src \'self\' \'unsafe-inline\'; script-src-elem \'self\' domain.com \'unsafe-inline\' \'nonce-'.$nonce.'\'; style-src \'self\' domain.com \'unsafe-inline\' \'nonce-'.$nonce.'\'; style-src-elem \'self\' domain.com \'unsafe-inline\' \'nonce-'.$nonce.'\'', 'Content-Security-Policy-Report-Only' => 'default-src \'self\' domain-report-only.com; script-src \'self\' \'unsafe-inline\'; script-src-elem \'self\' domain-report-only.com \'unsafe-inline\' \'nonce-'.$nonce.'\'; style-src \'self\' domain-report-only.com \'unsafe-inline\' \'nonce-'.$nonce.'\'; style-src-elem \'self\' domain-report-only.com \'unsafe-inline\' \'nonce-'.$nonce.'\'', 'X-Content-Security-Policy' => null], + ['Content-Security-Policy' => 'default-src \'self\' domain.com; script-src \'self\' \'unsafe-inline\'; style-src \'self\' domain.com \'unsafe-inline\' \'nonce-'.$nonce.'\'', 'Content-Security-Policy-Report-Only' => 'default-src \'self\' domain-report-only.com; script-src \'self\' \'unsafe-inline\'; style-src \'self\' domain-report-only.com \'unsafe-inline\' \'nonce-'.$nonce.'\'', 'X-Content-Security-Policy' => null], + ], + [ + $nonce, + ['csp_script_nonce' => $nonce, 'csp_style_nonce' => $nonce], + $this->createRequest(), + $this->createResponse(['Content-Security-Policy' => 'default-src \'self\' domain.com; script-src \'self\' \'unsafe-inline\'; script-src-elem \'self\'; style-src \'self\' \'unsafe-inline\'; style-src-elem \'self\'', 'Content-Security-Policy-Report-Only' => 'default-src \'self\' domain-report-only.com; script-src \'self\' \'unsafe-inline\'; script-src-elem \'self\'; style-src \'self\' \'unsafe-inline\'; style-src-elem \'self\'']), + ['Content-Security-Policy' => 'default-src \'self\' domain.com; script-src \'self\' \'unsafe-inline\'; script-src-elem \'self\' \'unsafe-inline\' \'nonce-'.$nonce.'\'; style-src \'self\' \'unsafe-inline\'; style-src-elem \'self\' \'unsafe-inline\' \'nonce-'.$nonce.'\'', 'Content-Security-Policy-Report-Only' => 'default-src \'self\' domain-report-only.com; script-src \'self\' \'unsafe-inline\'; script-src-elem \'self\' \'unsafe-inline\' \'nonce-'.$nonce.'\'; style-src \'self\' \'unsafe-inline\'; style-src-elem \'self\' \'unsafe-inline\' \'nonce-'.$nonce.'\'', 'X-Content-Security-Policy' => null], ], [ $nonce, From 00e727ae4ede5d8161caff4007e9cf7830d9d830 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Rish=C3=B8j?= Date: Wed, 22 Apr 2020 19:34:57 +0200 Subject: [PATCH 11/11] [Filesystem] Handle paths on different drives --- .../Component/Filesystem/Filesystem.php | 35 +++++++++---------- .../Filesystem/Tests/FilesystemTest.php | 4 +++ 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index a8701533cb..e2812f8e22 100644 --- a/src/Symfony/Component/Filesystem/Filesystem.php +++ b/src/Symfony/Component/Filesystem/Filesystem.php @@ -455,28 +455,19 @@ class Filesystem $startPath = str_replace('\\', '/', $startPath); } - $stripDriveLetter = function ($path) { - if (\strlen($path) > 2 && ':' === $path[1] && '/' === $path[2] && ctype_alpha($path[0])) { - return substr($path, 2); - } - - return $path; + $splitDriveLetter = function ($path) { + return (\strlen($path) > 2 && ':' === $path[1] && '/' === $path[2] && ctype_alpha($path[0])) + ? [substr($path, 2), strtoupper($path[0])] + : [$path, null]; }; - $endPath = $stripDriveLetter($endPath); - $startPath = $stripDriveLetter($startPath); - - // Split the paths into arrays - $startPathArr = explode('/', trim($startPath, '/')); - $endPathArr = explode('/', trim($endPath, '/')); - - $normalizePathArray = function ($pathSegments, $absolute) { + $splitPath = function ($path, $absolute) { $result = []; - foreach ($pathSegments as $segment) { + foreach (explode('/', trim($path, '/')) as $segment) { if ('..' === $segment && ($absolute || \count($result))) { array_pop($result); - } elseif ('.' !== $segment) { + } elseif ('.' !== $segment && '' !== $segment) { $result[] = $segment; } } @@ -484,8 +475,16 @@ class Filesystem return $result; }; - $startPathArr = $normalizePathArray($startPathArr, static::isAbsolutePath($startPath)); - $endPathArr = $normalizePathArray($endPathArr, static::isAbsolutePath($endPath)); + list($endPath, $endDriveLetter) = $splitDriveLetter($endPath); + list($startPath, $startDriveLetter) = $splitDriveLetter($startPath); + + $startPathArr = $splitPath($startPath, static::isAbsolutePath($startPath)); + $endPathArr = $splitPath($endPath, static::isAbsolutePath($endPath)); + + if ($endDriveLetter && $startDriveLetter && $endDriveLetter != $startDriveLetter) { + // End path is on another drive, so no relative path exists + return $endDriveLetter.':/'.($endPathArr ? implode('/', $endPathArr).'/' : ''); + } // Find for which directory the common path stops $index = 0; diff --git a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php index e9e7784a3a..8ac80437fe 100644 --- a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php +++ b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php @@ -1111,10 +1111,14 @@ class FilesystemTest extends FilesystemTestCase ['/../aa/bb/cc', '/aa/dd/..', 'bb/cc/'], ['/../../aa/../bb/cc', '/aa/dd/..', '../bb/cc/'], ['C:/aa/bb/cc', 'C:/aa/dd/..', 'bb/cc/'], + ['C:/aa/bb/cc', 'c:/aa/dd/..', 'bb/cc/'], ['c:/aa/../bb/cc', 'c:/aa/dd/..', '../bb/cc/'], ['C:/aa/bb/../../cc', 'C:/aa/../dd/..', 'cc/'], ['C:/../aa/bb/cc', 'C:/aa/dd/..', 'bb/cc/'], ['C:/../../aa/../bb/cc', 'C:/aa/dd/..', '../bb/cc/'], + ['D:/', 'C:/aa/../bb/cc', 'D:/'], + ['D:/aa/bb', 'C:/aa', 'D:/aa/bb/'], + ['D:/../../aa/../bb/cc', 'C:/aa/dd/..', 'D:/bb/cc/'], ]; if ('\\' === \DIRECTORY_SEPARATOR) {