Skip to content

EspoCRM – Open Source CRM Application

Formula function trailing comma

Yurii52345b47799a
diff --git a/application/Espo/Core/Formula/Parser.php b/application/Espo/Core/Formula/Parser.php
index c069e4f4ae..78bec23779 100644
--- a/application/Espo/Core/Formula/Parser.php
+++ b/application/Espo/Core/Formula/Parser.php
@@ -1282,6 +1282,10 @@ class Parser
)
);
+ if ($argument === '' && $i === count($commaIndexList) - 1) {
+ continue;
+ }
+
$argumentList[] = $argument;
}
diff --git a/tests/unit/Espo/Core/Formula/EvaluatorTest.php b/tests/unit/Espo/Core/Formula/EvaluatorTest.php
index 360db3efff..b7378b8027 100644
--- a/tests/unit/Espo/Core/Formula/EvaluatorTest.php
+++ b/tests/unit/Espo/Core/Formula/EvaluatorTest.php
@@ -2117,4 +2117,25 @@ class EvaluatorTest extends TestCase
/** @noinspection PhpUnhandledExceptionInspection */
$this->evaluator->process($expression);
}
+
+ public function testFunctionArguments(): void
+ {
+ $expression = "
+ \$a = list(0, 1);
+ \$b = list(0, 1,);
+ \$c = list(
+ 0,
+ 1,
+ );
+ ";
+
+ $vars = (object) [];
+
+ /** @noinspection PhpUnhandledExceptionInspection */
+ $this->evaluator->process($expression, null, $vars);
+
+ $this->assertEquals([0, 1], $vars->a);
+ $this->assertEquals([0, 1], $vars->b);
+ $this->assertEquals([0, 1], $vars->c);
+ }
}