Skip to content

Commit

Permalink
fix(symfony): ECMA-262 pattern with RegExp validator
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka committed Oct 17, 2024
1 parent 4171d5f commit a0409fc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 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
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 a0409fc

Please sign in to comment.