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

[ExpressionLanguage] Fix matches to handle booleans being used as regexp #58261

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

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
2 changes: 2 additions & 0 deletions 2 src/Symfony/Component/ExpressionLanguage/Node/BinaryNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public function compile(Compiler $compiler): void
if ('matches' == $operator) {
if ($this->nodes['right'] instanceof ConstantNode) {
$this->evaluateMatches($this->nodes['right']->evaluate([], []), '');
} elseif ($this->nodes['right'] instanceof self && '~' !== $this->nodes['right']->attributes['operator']) {
throw new SyntaxError('The regex passed to "matches" must be a string.');
}

$compiler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,27 @@ public function testCompileMatchesWithInvalidRegexpAsExpression()
eval('$regexp = "this is not a regexp"; '.$compiler->getSource().';');
}

public function testCompileMatchesWithBooleanBinaryNode()
{
$binaryNode = new BinaryNode('||', new ConstantNode(true), new ConstantNode(false));
$node = new BinaryNode('matches', new ConstantNode('abc'), $binaryNode);

$this->expectException(SyntaxError::class);
$this->expectExceptionMessage('The regex passed to "matches" must be a string');
$compiler = new Compiler([]);
$node->compile($compiler);
}

public function testCompileMatchesWithStringBinaryNode()
{
$binaryNode = new BinaryNode('~', new ConstantNode('a'), new ConstantNode('b'));
$node = new BinaryNode('matches', new ConstantNode('abc'), $binaryNode);

$compiler = new Compiler([]);
$node->compile($compiler);
$this->expectNotToPerformAssertions();
}

public function testDivisionByZero()
{
$node = new BinaryNode('/', new ConstantNode(1), new ConstantNode(0));
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.