This is an automated email from the ASF dual-hosted git repository.

kxiao pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 94969e734314836839fec61ca5099bc441572423
Author: DongLiang-0 <[email protected]>
AuthorDate: Sun Oct 8 10:09:17 2023 +0800

    [fix](help-module)fix use regex match replaceAll may cause backtracking 
(#24918)
---
 .../main/java/org/apache/doris/common/MarkDownParser.java | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/common/MarkDownParser.java 
b/fe/fe-core/src/main/java/org/apache/doris/common/MarkDownParser.java
index 200c1060036..e796f766d99 100755
--- a/fe/fe-core/src/main/java/org/apache/doris/common/MarkDownParser.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/common/MarkDownParser.java
@@ -169,6 +169,19 @@ public class MarkDownParser {
         // Also, the header in md file is like "## STREAM-LOAD", we need to 
convert it to "STREAM LOAD",
         // so that we can execute "help stream load" to show the help doc.
         return 
Maps.immutableEntry(key.substring(headLevel).trim().replaceAll("-", " "),
-                sb.toString().replaceAll("\\s+$", "\n"));
+                processWhitespace(sb));
+    }
+
+    private String processWhitespace(StringBuilder sb) {
+        int index = sb.length() - 1;
+        while (index >= 0 && Character.isWhitespace(sb.charAt(index))) {
+            index--;
+        }
+
+        if (index < sb.length() - 1) {
+            sb.setLength(index + 1);
+            sb.append('\n');
+        }
+        return sb.toString();
     }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to