From d761278853cad06841b87dcbc3739d3fdcf3d8af Mon Sep 17 00:00:00 2001 From: Guilliam Xavier Date: Wed, 31 Mar 2021 12:05:53 +0200 Subject: [PATCH 1/3] Fix PropertySchemaRegexRestriction pattern anchor --- .../Property/Restriction/PropertySchemaRegexRestriction.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bridge/Symfony/Validator/Metadata/Property/Restriction/PropertySchemaRegexRestriction.php b/src/Bridge/Symfony/Validator/Metadata/Property/Restriction/PropertySchemaRegexRestriction.php index 167152748c8..18077acf25e 100644 --- a/src/Bridge/Symfony/Validator/Metadata/Property/Restriction/PropertySchemaRegexRestriction.php +++ b/src/Bridge/Symfony/Validator/Metadata/Property/Restriction/PropertySchemaRegexRestriction.php @@ -29,7 +29,7 @@ class PropertySchemaRegexRestriction implements PropertySchemaRestrictionMetadat */ public function create(Constraint $constraint, PropertyMetadata $propertyMetadata): array { - return $constraint instanceof Regex && $constraint->getHtmlPattern() ? ['pattern' => $constraint->getHtmlPattern()] : []; + return $constraint instanceof Regex && $constraint->getHtmlPattern() ? ['pattern' => '^(?:'.$constraint->getHtmlPattern().')$'] : []; } /** From bd06e0b5e895735666b8ba91806b269ccc771b9a Mon Sep 17 00:00:00 2001 From: Guilliam Xavier Date: Wed, 31 Mar 2021 12:09:30 +0200 Subject: [PATCH 2/3] Fix tests for Regex constraint to anchored pattern --- .../Property/ValidatorPropertyMetadataFactoryTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Bridge/Symfony/Validator/Metadata/Property/ValidatorPropertyMetadataFactoryTest.php b/tests/Bridge/Symfony/Validator/Metadata/Property/ValidatorPropertyMetadataFactoryTest.php index f7c59d07666..98b8cb8d88b 100644 --- a/tests/Bridge/Symfony/Validator/Metadata/Property/ValidatorPropertyMetadataFactoryTest.php +++ b/tests/Bridge/Symfony/Validator/Metadata/Property/ValidatorPropertyMetadataFactoryTest.php @@ -305,7 +305,7 @@ public function testCreateWithPropertyRegexRestriction(): void $schema = $validationPropertyMetadataFactory->create(DummyValidatedEntity::class, 'dummy')->getSchema(); $this->assertNotNull($schema); $this->assertArrayHasKey('pattern', $schema); - $this->assertEquals('dummy', $schema['pattern']); + $this->assertEquals('^(?:dummy)$', $schema['pattern']); } public function testCreateWithPropertyFormatRestriction(): void @@ -402,7 +402,7 @@ public function testCreateWithAtLeastOneOfConstraint(): void $this->assertNotNull($schema); $this->assertArrayHasKey('oneOf', $schema); $this->assertSame([ - ['pattern' => '.*#.*'], + ['pattern' => '^(?:.*#.*)$'], ['minLength' => 10], ], $schema['oneOf']); } From 030b226be010b826c08fee44160c9cbc40f471a8 Mon Sep 17 00:00:00 2001 From: Guilliam Xavier Date: Wed, 31 Mar 2021 12:18:19 +0200 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 50351ba7727..cb140038f96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ * Doctrine: Revert #3774 support for binary UUID in search filter (#4134) * Do not override Vary headers already set in the Response * GraphQL: Make sure the order of order filters is preserved if nested resources are used (#4171) +* Validation: properties regex pattern is now correctly anchored (#4176) ## 2.6.3