Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(symfony): ECMA-262 pattern with RegExp validator #6733

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
Loading