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 464385f

Browse filesBrowse files
committed
bug #45928 [ExpressionLanguage] Fix matching null against a regular expression (ausi)
This PR was squashed before being merged into the 4.4 branch. Discussion ---------- [ExpressionLanguage] Fix matching null against a regular expression | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #45926 | License | MIT | Doc PR | - As discussed in #45926 (comment) The bug was introduced by #45875 Commits ------- 3326da0 [ExpressionLanguage] Fix matching null against a regular expression
2 parents 1ffe8ef + 3326da0 commit 464385f
Copy full SHA for 464385f

File tree

2 files changed

+6
-4
lines changed
Filter options

2 files changed

+6
-4
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/ExpressionLanguage/Node/BinaryNode.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function compile(Compiler $compiler)
5252
}
5353

5454
$compiler
55-
->raw('(static function ($regexp, $str) { set_error_handler(function ($t, $m) use ($regexp, $str) { throw new \Symfony\Component\ExpressionLanguage\SyntaxError(sprintf(\'Regexp "%s" passed to "matches" is not valid\', $regexp).substr($m, 12)); }); try { return preg_match($regexp, $str); } finally { restore_error_handler(); } })(')
55+
->raw('(static function ($regexp, $str) { set_error_handler(function ($t, $m) use ($regexp, $str) { throw new \Symfony\Component\ExpressionLanguage\SyntaxError(sprintf(\'Regexp "%s" passed to "matches" is not valid\', $regexp).substr($m, 12)); }); try { return preg_match($regexp, (string) $str); } finally { restore_error_handler(); } })(')
5656
->compile($this->nodes['right'])
5757
->raw(', ')
5858
->compile($this->nodes['left'])
@@ -173,13 +173,13 @@ public function toArray()
173173
return ['(', $this->nodes['left'], ' '.$this->attributes['operator'].' ', $this->nodes['right'], ')'];
174174
}
175175

176-
private function evaluateMatches(string $regexp, string $str): int
176+
private function evaluateMatches(string $regexp, ?string $str): int
177177
{
178178
set_error_handler(function ($t, $m) use ($regexp) {
179179
throw new SyntaxError(sprintf('Regexp "%s" passed to "matches" is not valid', $regexp).substr($m, 12));
180180
});
181181
try {
182-
return preg_match($regexp, $str);
182+
return preg_match($regexp, (string) $str);
183183
} finally {
184184
restore_error_handler();
185185
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/ExpressionLanguage/Tests/Node/BinaryNodeTest.php
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ public function getEvaluateData()
6666
[[1, 2, 3], new BinaryNode('..', new ConstantNode(1), new ConstantNode(3))],
6767

6868
[1, new BinaryNode('matches', new ConstantNode('abc'), new ConstantNode('/^[a-z]+$/'))],
69+
[0, new BinaryNode('matches', new ConstantNode(''), new ConstantNode('/^[a-z]+$/'))],
70+
[0, new BinaryNode('matches', new ConstantNode(null), new ConstantNode('/^[a-z]+$/'))],
6971
];
7072
}
7173

@@ -114,7 +116,7 @@ public function getCompileData()
114116

115117
['range(1, 3)', new BinaryNode('..', new ConstantNode(1), new ConstantNode(3))],
116118

117-
['(static function ($regexp, $str) { set_error_handler(function ($t, $m) use ($regexp, $str) { throw new \Symfony\Component\ExpressionLanguage\SyntaxError(sprintf(\'Regexp "%s" passed to "matches" is not valid\', $regexp).substr($m, 12)); }); try { return preg_match($regexp, $str); } finally { restore_error_handler(); } })("/^[a-z]+\$/", "abc")', new BinaryNode('matches', new ConstantNode('abc'), new ConstantNode('/^[a-z]+$/'))],
119+
['(static function ($regexp, $str) { set_error_handler(function ($t, $m) use ($regexp, $str) { throw new \Symfony\Component\ExpressionLanguage\SyntaxError(sprintf(\'Regexp "%s" passed to "matches" is not valid\', $regexp).substr($m, 12)); }); try { return preg_match($regexp, (string) $str); } finally { restore_error_handler(); } })("/^[a-z]+\$/", "abc")', new BinaryNode('matches', new ConstantNode('abc'), new ConstantNode('/^[a-z]+$/'))],
118120
];
119121
}
120122

0 commit comments

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