File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed
src/Symfony/Component/ExpressionLanguage Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -52,6 +52,8 @@ public function compile(Compiler $compiler): void
52
52
if ('matches ' == $ operator ) {
53
53
if ($ this ->nodes ['right ' ] instanceof ConstantNode) {
54
54
$ 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. ' );
55
57
}
56
58
57
59
$ compiler
Original file line number Diff line number Diff line change @@ -221,6 +221,27 @@ public function testCompileMatchesWithInvalidRegexpAsExpression()
221
221
eval ('$regexp = "this is not a regexp"; ' .$ compiler ->getSource ().'; ' );
222
222
}
223
223
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
+
224
245
public function testDivisionByZero ()
225
246
{
226
247
$ node = new BinaryNode ('/ ' , new ConstantNode (1 ), new ConstantNode (0 ));
You can’t perform that action at this time.
0 commit comments