formula strict syntax

This commit is contained in:
Yuri Kuznetsov
2022-01-13 17:56:19 +02:00
parent 491a66ac4c
commit 23a54a0fa4
2 changed files with 19 additions and 0 deletions
+10
View File
@@ -66,6 +66,8 @@ class Parser
private $variableNameRegExp = "/^[a-zA-Z0-9_\$]+$/";
private $functionNameRegExp = "/^[a-zA-Z0-9_\\\\]+$/";
public function parse(string $expression): stdClass
{
return $this->split($expression);
@@ -115,6 +117,10 @@ class Parser
$functionName = $this->operatorMap[$operator];
if ($functionName === '' || !preg_match($this->functionNameRegExp, $functionName)) {
throw new SyntaxError("Bad function name `{$functionName}`.");
}
return (object) [
'type' => $functionName,
'value' => [
@@ -527,6 +533,10 @@ class Parser
$argumentSplittedList[] = $this->split($argument);
}
if ($functionName === '' || !preg_match($this->functionNameRegExp, $functionName)) {
throw new SyntaxError("Bad function name `{$functionName}`.");
}
return (object) [
'type' => $functionName,
'value' => $argumentSplittedList,
@@ -589,4 +589,13 @@ class EvaluatorTest extends \PHPUnit\Framework\TestCase
$this->evaluator->process($expression, null);
}
public function testSyntaxError9(): void
{
$expression = "test.test('test')";
$this->expectException(SyntaxError::class);
$this->evaluator->process($expression, null);
}
}