From d266e80173126eaf6dbfee4333be6cb0833c39bf Mon Sep 17 00:00:00 2001 From: Philipp Ossler Date: Thu, 29 Aug 2024 10:13:28 +0200 Subject: [PATCH] fix: Handle escape sequences Correct the handling of escape sequences in string literals. Don't replace escape sequences in regex expressions, for example, \r or \n. In the parser, these sequences start with \\. Same for \s, don't replace it with a whitespace, since this is also a part of a regex. Handle \\ to avoid that the sequence is escaped and returned as \\\\. --- .../camunda/feel/impl/parser/FeelParser.scala | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 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 144a94a7b..4086fa208 100644 --- a/src/main/scala/org/camunda/feel/impl/parser/FeelParser.scala +++ b/src/main/scala/org/camunda/feel/impl/parser/FeelParser.scala @@ -694,22 +694,16 @@ object FeelParser { }.getOrElse(ConstNull) } - // replace escaped character with the provided replacement private def translateEscapes(input: String): String = { - val escapeMap = Map( - "\\b" -> "\b", - "\\t" -> "\t", - "\\n" -> "\n", - "\\f" -> "\f", - "\\r" -> "\r", - "\\\"" -> "\"", - "\\'" -> "'", - "\\s" -> " " - // Add more escape sequences as needed - ) - - escapeMap.foldLeft(input) { case (result, (escape, replacement)) => - result.replace(escape, replacement) - } + // replace all escape sequences + input + .replaceAll("(?