From 4952fbfedb8b018f9a2fb30854292e087774e3ae Mon Sep 17 00:00:00 2001 From: sjgllgh Date: Wed, 29 Nov 2023 11:05:13 +0800 Subject: [PATCH] 1.format source code 2.add code comment --- .../entrance/interceptor/impl/CommentInterceptor.scala | 6 ++++++ .../entrance/interceptor/impl/TestReplaceComment.scala | 1 - 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/linkis-computation-governance/linkis-entrance/src/main/scala/org/apache/linkis/entrance/interceptor/impl/CommentInterceptor.scala b/linkis-computation-governance/linkis-entrance/src/main/scala/org/apache/linkis/entrance/interceptor/impl/CommentInterceptor.scala index f1d7fb1e1a..de0bcc376f 100644 --- a/linkis-computation-governance/linkis-entrance/src/main/scala/org/apache/linkis/entrance/interceptor/impl/CommentInterceptor.scala +++ b/linkis-computation-governance/linkis-entrance/src/main/scala/org/apache/linkis/entrance/interceptor/impl/CommentInterceptor.scala @@ -81,6 +81,12 @@ object SQLCommentHelper extends CommentHelper { while (matcher.find()) { val commentKeyword = matcher.group(1) val comment = matcher.group(2) + + /** + * Since we are in a Scala string, and each backslash needs to be escaped in the string + * itself, we need two additional backslashes. Therefore, we end up with a total of four + * backslashes to represent a single literal backslash in the replacement string. + */ val escapedComment = comment.replaceAll(";", "\\\\\\\\;") matcher.appendReplacement(sb, commentKeyword + " '" + escapedComment + "'") } diff --git a/linkis-computation-governance/linkis-entrance/src/test/scala/org/apache/linkis/entrance/interceptor/impl/TestReplaceComment.scala b/linkis-computation-governance/linkis-entrance/src/test/scala/org/apache/linkis/entrance/interceptor/impl/TestReplaceComment.scala index 5f26a228de..3310f09581 100644 --- a/linkis-computation-governance/linkis-entrance/src/test/scala/org/apache/linkis/entrance/interceptor/impl/TestReplaceComment.scala +++ b/linkis-computation-governance/linkis-entrance/src/test/scala/org/apache/linkis/entrance/interceptor/impl/TestReplaceComment.scala @@ -21,7 +21,6 @@ import org.junit.jupiter.api.{Assertions, Test} class TestReplaceComment { - @Test def TestRepComm: Unit = { val realCode = "drop table if exists default.test;" +