diff --git a/application/Espo/Core/Formula/Parser.php b/application/Espo/Core/Formula/Parser.php index 5b2df13582..5f11916a52 100644 --- a/application/Espo/Core/Formula/Parser.php +++ b/application/Espo/Core/Formula/Parser.php @@ -251,7 +251,6 @@ class Parser $expression = trim($expression); $braceCounter = 0; - $singleQuoteCounter = 0; $hasExcessBraces = true; $modifiedExpression = ''; $splitterIndexList = []; @@ -346,7 +345,7 @@ class Parser $firstOperator = null; $minIndex = null; - if ($expression === '') { + if (trim($expression) === '') { return (object) [ 'type' => 'value', 'value' => null, @@ -370,6 +369,7 @@ class Parser $startFrom = $index + 1; } + if ($index !== false) { $possibleRightOperator = null; @@ -413,10 +413,8 @@ class Parser $this->processStrings($secondPart, $modifiedSecondPart); if ( - substr_count($modifiedFirstPart, '(') === substr_count($modifiedFirstPart, ')') - && - substr_count($modifiedSecondPart, '(') === substr_count($modifiedSecondPart, ')') - && + substr_count($modifiedFirstPart, '(') === substr_count($modifiedFirstPart, ')') && + substr_count($modifiedSecondPart, '(') === substr_count($modifiedSecondPart, ')') && !$isString ) { if ($minIndex === null) { @@ -452,10 +450,6 @@ class Parser $expression = trim($expression); - if ($expression === '') { - throw SyntaxError::create("Empty attribute."); - } - if ($expression[0] === '!') { return (object) [ 'type' => 'logical\\not', @@ -524,13 +518,15 @@ class Parser 'value' => true, ]; } - else if ($expression === 'false') { + + if ($expression === 'false') { return (object) [ 'type' => 'value', 'value' => false, ]; } - else if ($expression === 'null') { + + if ($expression === 'null') { return (object) [ 'type' => 'value', 'value' => null, diff --git a/tests/unit/Espo/Core/Formula/EvaluatorTest.php b/tests/unit/Espo/Core/Formula/EvaluatorTest.php index bc28a109d8..f03003f4eb 100644 --- a/tests/unit/Espo/Core/Formula/EvaluatorTest.php +++ b/tests/unit/Espo/Core/Formula/EvaluatorTest.php @@ -990,4 +990,18 @@ class EvaluatorTest extends \PHPUnit\Framework\TestCase $this->evaluator->process($expression, null) ); } + + public function testEmpty1(): void + { + $expression = " "; + + $this->assertNull($this->evaluator->process($expression, null)); + } + + public function testOnlyComment(): void + { + $expression = " // test"; + + $this->assertNull($this->evaluator->process($expression, null)); + } }