Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4807dab

Browse filesBrowse files
xabbuhnicolas-grekas
authored andcommitted
[Validator] use "allowedVariables" to configure the ExpressionLanguageSyntax constraint
1 parent 2ff26b7 commit 4807dab
Copy full SHA for 4807dab

File tree

3 files changed

+7
-6
lines changed
Filter options

3 files changed

+7
-6
lines changed

‎src/Symfony/Component/Validator/Constraints/ExpressionLanguageSyntax.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/ExpressionLanguageSyntax.php
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ class ExpressionLanguageSyntax extends Constraint
2929

3030
public $message = 'This value should be a valid expression.';
3131
public $service;
32-
public $validateNames = true;
33-
public $names = [];
32+
public $allowedVariables = null;
3433

3534
/**
3635
* {@inheritdoc}

‎src/Symfony/Component/Validator/Constraints/ExpressionLanguageSyntaxValidator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/ExpressionLanguageSyntaxValidator.php
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Validator\Constraint;
1717
use Symfony\Component\Validator\ConstraintValidator;
1818
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
19+
use Symfony\Component\Validator\Exception\UnexpectedValueException;
1920

2021
/**
2122
* @author Andrey Sevastianov <mrpkmail@gmail.com>
@@ -39,15 +40,15 @@ public function validate($expression, Constraint $constraint): void
3940
}
4041

4142
if (!\is_string($expression)) {
42-
throw new UnexpectedTypeException($expression, 'string');
43+
throw new UnexpectedValueException($expression, 'string');
4344
}
4445

4546
if (null === $this->expressionLanguage) {
4647
$this->expressionLanguage = new ExpressionLanguage();
4748
}
4849

4950
try {
50-
$this->expressionLanguage->lint($expression, ($constraint->validateNames ? ($constraint->names ?? []) : null));
51+
$this->expressionLanguage->lint($expression, $constraint->allowedVariables);
5152
} catch (SyntaxError $exception) {
5253
$this->context->buildViolation($constraint->message)
5354
->setParameter('{{ syntax_error }}', $this->formatValue($exception->getMessage()))

‎src/Symfony/Component/Validator/Tests/Constraints/ExpressionLanguageSyntaxTest.php renamed to ‎src/Symfony/Component/Validator/Tests/Constraints/ExpressionLanguageSyntaxValidatorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Tests/Constraints/ExpressionLanguageSyntaxValidatorTest.php
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use Symfony\Component\Validator\Constraints\ExpressionLanguageSyntaxValidator;
1919
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
2020

21-
class ExpressionLanguageSyntaxTest extends ConstraintValidatorTestCase
21+
class ExpressionLanguageSyntaxValidatorTest extends ConstraintValidatorTestCase
2222
{
2323
/**
2424
* @var \PHPUnit\Framework\MockObject\MockObject|ExpressionLanguage
@@ -45,6 +45,7 @@ public function testExpressionValid(): void
4545

4646
$this->validator->validate($this->value, new ExpressionLanguageSyntax([
4747
'message' => 'myMessage',
48+
'allowedVariables' => [],
4849
]));
4950

5051
$this->assertNoViolation();
@@ -58,7 +59,6 @@ public function testExpressionWithoutNames(): void
5859

5960
$this->validator->validate($this->value, new ExpressionLanguageSyntax([
6061
'message' => 'myMessage',
61-
'validateNames' => false,
6262
]));
6363

6464
$this->assertNoViolation();
@@ -73,6 +73,7 @@ public function testExpressionIsNotValid(): void
7373

7474
$this->validator->validate($this->value, new ExpressionLanguageSyntax([
7575
'message' => 'myMessage',
76+
'allowedVariables' => [],
7677
]));
7778

7879
$this->buildViolation('myMessage')

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.