From f71719978cb122d019cad7b2002ef1755fa83a76 Mon Sep 17 00:00:00 2001 From: Philipp Ossler Date: Tue, 19 Dec 2023 15:34:49 +0100 Subject: [PATCH 1/2] test: Verify escaping of double quotes Add a test case to verify that double quotes are properly escaped in a string literal. --- .../impl/interpreter/InterpreterStringExpressionTest.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/test/scala/org/camunda/feel/impl/interpreter/InterpreterStringExpressionTest.scala b/src/test/scala/org/camunda/feel/impl/interpreter/InterpreterStringExpressionTest.scala index 3e3c292ca..a4b438283 100644 --- a/src/test/scala/org/camunda/feel/impl/interpreter/InterpreterStringExpressionTest.scala +++ b/src/test/scala/org/camunda/feel/impl/interpreter/InterpreterStringExpressionTest.scala @@ -93,11 +93,13 @@ class InterpreterStringExpressionTest evaluateExpression(""" "Hello\tWorld" """) should returnResult("Hello\tWorld") evaluateExpression(" x ", Map("x" -> "Hello\tWorld")) should returnResult("Hello\tWorld") + + evaluateExpression(""" "Hello\"World" """) should returnResult("Hello\"World") + evaluateExpression(" x ", Map("x" -> "Hello\"World")) should returnResult("Hello\"World") } List( " \' ", - " \\\" ", " \\ ", " \n ", " \r ", From 630ce93b8f250bb63dda2a5781125b2927536be3 Mon Sep 17 00:00:00 2001 From: Philipp Ossler Date: Tue, 19 Dec 2023 15:41:38 +0100 Subject: [PATCH 2/2] fix: Handle escaped quotes in strings We should handle escaped double quotes in string literals properly (e.g. `"hello \"FEEL\"!"`). Currently, the quotes are doubled escaped (`"hello \\\"FEEL\\\"!"` but should be `"hello \"FEEL\"!"`). Move the translation of the escape characters to the parsing of the string literal because only string literal can contain these characters. Translating the whole expression would break the parsing. --- .../scala/org/camunda/feel/impl/parser/FeelParser.scala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/scala/org/camunda/feel/impl/parser/FeelParser.scala b/src/main/scala/org/camunda/feel/impl/parser/FeelParser.scala index 8bed34f97..d90032723 100644 --- a/src/main/scala/org/camunda/feel/impl/parser/FeelParser.scala +++ b/src/main/scala/org/camunda/feel/impl/parser/FeelParser.scala @@ -123,10 +123,10 @@ import scala.util.Try object FeelParser { def parseExpression(expression: String): Parsed[Exp] = - parse(translateEscapes(expression), fullExpression(_)) + parse(expression, fullExpression(_)) def parseUnaryTests(expression: String): Parsed[Exp] = - parse(translateEscapes(expression), fullUnaryExpression(_)) + parse(expression, fullUnaryExpression(_)) // --------------- entry parsers --------------- @@ -391,7 +391,7 @@ object FeelParser { private def string[_: P]: P[Exp] = P( stringWithQuotes - ).map(ConstString) + ).map(translateEscapes).map(ConstString) private def number[_: P]: P[Exp] = P( @@ -697,7 +697,7 @@ object FeelParser { "\\n" -> "\n", "\\f" -> "\f", "\\r" -> "\r", - "\"" -> "\"", + "\\\"" -> "\"", "\\'" -> "'", "\\s" -> " " // Add more escape sequences as needed