Skip to content

Commit

Permalink
fix(symfony): ECMA-262 pattern with RegExp validator (#6733)
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka authored Oct 25, 2024
1 parent cecd771 commit 5a8ef11
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private function addSchemaValidation(Parameter $parameter, ?array $schema = null
}

if (isset($schema['pattern'])) {
$assertions[] = new Regex($schema['pattern']);
$assertions[] = new Regex('#'.$schema['pattern'].'#');
}

if (isset($schema['maxLength']) || isset($schema['minLength'])) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/TestBundle/ApiResource/WithParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
'length' => new QueryParameter(schema: ['maxLength' => 1, 'minLength' => 3]),
'array' => new QueryParameter(schema: ['minItems' => 2, 'maxItems' => 3]),
'multipleOf' => new QueryParameter(schema: ['multipleOf' => 2]),
'pattern' => new QueryParameter(schema: ['pattern' => '/\d/']),
'pattern' => new QueryParameter(schema: ['pattern' => '\d']),
],
provider: [self::class, 'collectionProvider']
)]
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/TestBundle/Filter/PatternFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function getDescription(string $resourceClass): array
'type' => 'string',
'required' => false,
'schema' => [
'pattern' => '/^(pattern|nrettap)$/',
'pattern' => '^(pattern|nrettap)$',
],
],
];
Expand Down
8 changes: 7 additions & 1 deletion tests/Functional/Parameters/ValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public static function provideQueryStrings(): array

public function testBlank(): void
{
$response = self::createClient()->request('GET', 'validate_parameters?blank=f');
self::createClient()->request('GET', 'validate_parameters?blank=f');
$this->assertResponseIsSuccessful();
}

Expand Down Expand Up @@ -146,4 +146,10 @@ public function testValidatePropertyPlaceholder(): void
],
], $response->toArray(false));
}

public function testValidatePattern(): void
{
self::createClient()->request('GET', 'validate_parameters?pattern=2');
$this->assertResponseIsSuccessful();
}
}

0 comments on commit 5a8ef11

Please sign in to comment.