From 38ce78fceda27dcebb6eb1d7d27bdb95fa0a34ee Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Wed, 24 Apr 2024 13:33:52 +0300 Subject: [PATCH] formula fix string double backslash and quote --- application/Espo/Core/Formula/Parser.php | 2 +- .../unit/Espo/Core/Formula/EvaluatorTest.php | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/application/Espo/Core/Formula/Parser.php b/application/Espo/Core/Formula/Parser.php index a7fd43139a..1e5014768b 100644 --- a/application/Espo/Core/Formula/Parser.php +++ b/application/Espo/Core/Formula/Parser.php @@ -144,7 +144,7 @@ class Parser { return ($string[$i - 1] ?? null) !== "\\" || - ($string[$i - 2] ?? null) === "\\"; + (($string[$i - 2] ?? null) === "\\" && ($string[$i - 3] ?? null) !== "\\"); } /** diff --git a/tests/unit/Espo/Core/Formula/EvaluatorTest.php b/tests/unit/Espo/Core/Formula/EvaluatorTest.php index 499eaaa68c..e48b1bcaa7 100644 --- a/tests/unit/Espo/Core/Formula/EvaluatorTest.php +++ b/tests/unit/Espo/Core/Formula/EvaluatorTest.php @@ -1499,4 +1499,24 @@ class EvaluatorTest extends \PHPUnit\Framework\TestCase $this->assertEquals("\n\\test\n", $result); } + + public function testStrings8(): void + { + $expression = '"\\\\\\""'; + + /** @noinspection PhpUnhandledExceptionInspection */ + $result = $this->evaluator->process($expression); + + $this->assertEquals("\\\"", $result); + } + + public function testStrings9(): void + { + $expression = '"\\\\\\"test\\\\\\""'; + + /** @noinspection PhpUnhandledExceptionInspection */ + $result = $this->evaluator->process($expression); + + $this->assertEquals("\\\"test\\\"", $result); + } }