Skip to content

Commit

Permalink
pattern must be compliant with ECMA 262 regex (#4027)
Browse files Browse the repository at this point in the history
  • Loading branch information
stchr committed Feb 6, 2021
1 parent 8a00d6e commit 8a16c9d
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class PropertySchemaRegexRestriction implements PropertySchemaRestrictionMetadat
*/
public function create(Constraint $constraint, PropertyMetadata $propertyMetadata): array
{
return isset($constraint->pattern) ? ['pattern' => $constraint->pattern] : [];
return $constraint instanceof Regex && $constraint->getHtmlPattern() ? ['pattern' => $constraint->getHtmlPattern()] : [];
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,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
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/DummyValidatedEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class DummyValidatedEntity
*
* @Assert\NotBlank
* @Assert\Length(max="4", min="10")
* @Assert\Regex(pattern="^dummy$")
* @Assert\Regex(pattern="/^dummy$/")
*/
public $dummy;

Expand Down

0 comments on commit 8a16c9d

Please sign in to comment.