fix parser

This commit is contained in:
Yuri Kuznetsov
2024-05-04 23:00:46 +03:00
parent 71dd872618
commit cbec1cbbe5
2 changed files with 15 additions and 3 deletions
+3 -3
View File
@@ -861,7 +861,7 @@ class Parser
$offset = -1;
while (true) {
$index = strrpos($expression, $operator, $offset);
$index = strrpos($modifiedExpression, $operator, $offset);
if ($index === false) {
break;
@@ -882,7 +882,7 @@ class Parser
if (strlen($operator) === 1) {
if ($index < strlen($expression) - 1) {
$possibleRightOperator = trim($operator . $expression[$index + 1]);
$possibleRightOperator = trim($operator . $modifiedExpression[$index + 1]);
}
}
@@ -898,7 +898,7 @@ class Parser
if (strlen($operator) === 1) {
if ($index > 0) {
$possibleLeftOperator = trim($expression[$index - 1] . $operator);
$possibleLeftOperator = trim($modifiedExpression[$index - 1] . $operator);
}
}
@@ -1380,4 +1380,16 @@ class EvaluatorTest extends \PHPUnit\Framework\TestCase
$this->assertEquals(2, $vars->j);;
}
public function testStringsWithOperator(): void
{
$expression = "\$a = '='";
$vars = (object) [];
/** @noinspection PhpUnhandledExceptionInspection */
$this->evaluator->process($expression, null, $vars);
$this->assertEquals("=", $vars->a);
}
}