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 e0fbc7e

Browse filesBrowse files
ivantseppfabpot
authored andcommitted
[ExpressionLanguage] Fix matches to handle booleans being used as regexp
1 parent 4e70834 commit e0fbc7e
Copy full SHA for e0fbc7e

File tree

Expand file treeCollapse file tree

2 files changed

+23
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+23
-0
lines changed

‎src/Symfony/Component/ExpressionLanguage/Node/BinaryNode.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/ExpressionLanguage/Node/BinaryNode.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public function compile(Compiler $compiler): void
5252
if ('matches' == $operator) {
5353
if ($this->nodes['right'] instanceof ConstantNode) {
5454
$this->evaluateMatches($this->nodes['right']->evaluate([], []), '');
55+
} elseif ($this->nodes['right'] instanceof self && '~' !== $this->nodes['right']->attributes['operator']) {
56+
throw new SyntaxError('The regex passed to "matches" must be a string.');
5557
}
5658

5759
$compiler

‎src/Symfony/Component/ExpressionLanguage/Tests/Node/BinaryNodeTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/ExpressionLanguage/Tests/Node/BinaryNodeTest.php
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,27 @@ public function testCompileMatchesWithInvalidRegexpAsExpression()
221221
eval('$regexp = "this is not a regexp"; '.$compiler->getSource().';');
222222
}
223223

224+
public function testCompileMatchesWithBooleanBinaryNode()
225+
{
226+
$binaryNode = new BinaryNode('||', new ConstantNode(true), new ConstantNode(false));
227+
$node = new BinaryNode('matches', new ConstantNode('abc'), $binaryNode);
228+
229+
$this->expectException(SyntaxError::class);
230+
$this->expectExceptionMessage('The regex passed to "matches" must be a string');
231+
$compiler = new Compiler([]);
232+
$node->compile($compiler);
233+
}
234+
235+
public function testCompileMatchesWithStringBinaryNode()
236+
{
237+
$binaryNode = new BinaryNode('~', new ConstantNode('a'), new ConstantNode('b'));
238+
$node = new BinaryNode('matches', new ConstantNode('abc'), $binaryNode);
239+
240+
$compiler = new Compiler([]);
241+
$node->compile($compiler);
242+
$this->expectNotToPerformAssertions();
243+
}
244+
224245
public function testDivisionByZero()
225246
{
226247
$node = new BinaryNode('/', new ConstantNode(1), new ConstantNode(0));

0 commit comments

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