Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9645fa3

Browse files
fancywebxabbuh
authored andcommitted
[Validator][RecursiveContextualValidator] Prevent validated hash collisions
1 parentcdfa9c2 commit9645fa3

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

‎src/Symfony/Component/Validator/Tests/Validator/RecursiveValidatorTest.php‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@
1313

1414
usePHPUnit\Framework\TestCase;
1515
useSymfony\Component\Translation\IdentityTranslator;
16+
useSymfony\Component\Validator\Constraint;
1617
useSymfony\Component\Validator\Constraints\All;
1718
useSymfony\Component\Validator\Constraints\Callback;
1819
useSymfony\Component\Validator\Constraints\Collection;
1920
useSymfony\Component\Validator\Constraints\Expression;
2021
useSymfony\Component\Validator\Constraints\GroupSequence;
22+
useSymfony\Component\Validator\Constraints\IsFalse;
23+
useSymfony\Component\Validator\Constraints\IsNull;
2124
useSymfony\Component\Validator\Constraints\IsTrue;
2225
useSymfony\Component\Validator\Constraints\Length;
2326
useSymfony\Component\Validator\Constraints\NotBlank;
@@ -26,6 +29,7 @@
2629
useSymfony\Component\Validator\Constraints\Required;
2730
useSymfony\Component\Validator\Constraints\Traverse;
2831
useSymfony\Component\Validator\Constraints\Valid;
32+
useSymfony\Component\Validator\ConstraintValidator;
2933
useSymfony\Component\Validator\ConstraintValidatorFactory;
3034
useSymfony\Component\Validator\ConstraintViolationInterface;
3135
useSymfony\Component\Validator\Context\ExecutionContextFactory;
@@ -2135,4 +2139,47 @@ public function testOptionalConstraintIsIgnored()
21352139

21362140
$this->assertCount(0,$violations);
21372141
}
2142+
2143+
publicfunctiontestValidatedConstraintsHashesDoNotCollide()
2144+
{
2145+
$metadata =newClassMetadata(Entity::class);
2146+
$metadata->addPropertyConstraint('initialized',newNotNull(['groups' =>'should_pass']));
2147+
$metadata->addPropertyConstraint('initialized',newIsNull(['groups' =>'should_fail']));
2148+
2149+
$this->metadataFactory->addMetadata($metadata);
2150+
2151+
$entity =newEntity();
2152+
$entity->data =new \stdClass();
2153+
2154+
$this->assertCount(2,$this->validator->validate($entity,newTestConstraintHashesDoNotCollide()));
2155+
}
2156+
}
2157+
2158+
finalclass TestConstraintHashesDoNotCollideextends Constraint
2159+
{
2160+
}
2161+
2162+
finalclass TestConstraintHashesDoNotCollideValidatorextends ConstraintValidator
2163+
{
2164+
/**
2165+
* {@inheritdoc}
2166+
*/
2167+
publicfunctionvalidate($value,Constraint$constraint)
2168+
{
2169+
if (!$valueinstanceof Entity) {
2170+
thrownew \LogicException();
2171+
}
2172+
2173+
$this->context->getValidator()
2174+
->inContext($this->context)
2175+
->atPath('data')
2176+
->validate($value,newNotNull())
2177+
->validate($value,newNotNull())
2178+
->validate($value,newIsFalse());
2179+
2180+
$this->context->getValidator()
2181+
->inContext($this->context)
2182+
->validate($value,null,newGroupSequence(['should_pass']))
2183+
->validate($value,null,newGroupSequence(['should_fail']));
2184+
}
21382185
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp