Skip to content

Commit 4e7f35e

Browse files
authored
Merge pull request #46 from gepe82/fix-preg_match-pattern
add delimiter to preg_match pattern
2 parents d86718f + e4e4d54 commit 4e7f35e

File tree

5 files changed

+9
-5
lines changed

5 files changed

+9
-5
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## [6.0.1] - 2021-07-27
8+
### Fixed
9+
- Fix preg_match pattern by adding a slash (/) as a delimiter.
10+
711
## [6.0.0] - 2021-06-22
812
### Changed
913
- `enum` type are not anymore validated from generated client side.

src/Entity/Constraint/PatternConstraint.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
class PatternConstraint implements ConstraintInterface
1212
{
13-
private ?string $pattern = null;
13+
private ?string $pattern;
1414

1515
public function __construct(?string $pattern)
1616
{
@@ -30,7 +30,7 @@ public function exists(): bool
3030
public function getIfCondition(Variable $variable, CodeBuilder $builder): Expr
3131
{
3232
return $builder->notEquals(
33-
$builder->funcCall('preg_match', [$builder->val($this->pattern), $variable]),
33+
$builder->funcCall('preg_match', [$builder->val('/' . $this->pattern . '/'), $variable]),
3434
$builder->val(1)
3535
);
3636
}

test/suite/functional/Generator/Schema/ItemPhp70.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ public function setOptionalStringWithMinMaxLength(string $optionalStringWithMinM
249249
*/
250250
public function setOptionalStringWithPattern(string $optionalStringWithPattern): self
251251
{
252-
if (\preg_match('^\\d{3}-\\d{2}-\\d{4}$', $optionalStringWithPattern) !== 1) {
252+
if (\preg_match('/^\\d{3}-\\d{2}-\\d{4}$/', $optionalStringWithPattern) !== 1) {
253253
throw new RequestValidationException(\sprintf('Invalid %s value. Given: `%s`. Pattern is ^\\d{3}-\\d{2}-\\d{4}$.', 'optionalStringWithPattern', $optionalStringWithPattern));
254254
}
255255
$this->optionalStringWithPattern = $optionalStringWithPattern;

test/suite/functional/Generator/Schema/ItemPhp72.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ public function setOptionalStringWithMinMaxLength(string $optionalStringWithMinM
242242
*/
243243
public function setOptionalStringWithPattern(string $optionalStringWithPattern): self
244244
{
245-
if (\preg_match('^\\d{3}-\\d{2}-\\d{4}$', $optionalStringWithPattern) !== 1) {
245+
if (\preg_match('/^\\d{3}-\\d{2}-\\d{4}$/', $optionalStringWithPattern) !== 1) {
246246
throw new RequestValidationException(\sprintf('Invalid %s value. Given: `%s`. Pattern is ^\\d{3}-\\d{2}-\\d{4}$.', 'optionalStringWithPattern', $optionalStringWithPattern));
247247
}
248248
$this->optionalStringWithPattern = $optionalStringWithPattern;

test/suite/functional/Generator/Schema/ItemPhp74.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public function setOptionalStringWithMinMaxLength(string $optionalStringWithMinM
214214
*/
215215
public function setOptionalStringWithPattern(string $optionalStringWithPattern): self
216216
{
217-
if (\preg_match('^\\d{3}-\\d{2}-\\d{4}$', $optionalStringWithPattern) !== 1) {
217+
if (\preg_match('/^\\d{3}-\\d{2}-\\d{4}$/', $optionalStringWithPattern) !== 1) {
218218
throw new RequestValidationException(\sprintf('Invalid %s value. Given: `%s`. Pattern is ^\\d{3}-\\d{2}-\\d{4}$.', 'optionalStringWithPattern', $optionalStringWithPattern));
219219
}
220220
$this->optionalStringWithPattern = $optionalStringWithPattern;

0 commit comments

Comments
 (0)