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

dockerzhang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/inlong.git


The following commit(s) were added to refs/heads/master by this push:
     new 48c2f5cad4 [INLONG-11746][Manager] Fix the problem of JDBC URL cannot 
handle special characters (#11747)
48c2f5cad4 is described below

commit 48c2f5cad4a92be2c3561174d70cdbc91a2d2626
Author: fuweng11 <76141879+fuwen...@users.noreply.github.com>
AuthorDate: Tue Feb 11 17:28:35 2025 +0800

    [INLONG-11746][Manager] Fix the problem of JDBC URL cannot handle special 
characters (#11747)
---
 .../manager/common/consts/InlongConstants.java     |  2 +
 .../manager/pojo/util/MySQLSensitiveUrlUtils.java  | 54 ++++++++++++++++------
 .../manager/pojo/sink/mysql/MySQLSinkDTOTest.java  | 13 +++++-
 3 files changed, 52 insertions(+), 17 deletions(-)

diff --git 
a/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/consts/InlongConstants.java
 
b/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/consts/InlongConstants.java
index d9957e81f5..e7cc03602b 100644
--- 
a/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/consts/InlongConstants.java
+++ 
b/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/consts/InlongConstants.java
@@ -66,6 +66,8 @@ public class InlongConstants {
 
     public static final String LEFT_BRACKET = "(";
 
+    public static final String RIGHT_BRACKET = ")";
+
     public static final String PERCENT = "%";
 
     public static final String QUESTION_MARK = "?";
diff --git 
a/inlong-manager/manager-pojo/src/main/java/org/apache/inlong/manager/pojo/util/MySQLSensitiveUrlUtils.java
 
b/inlong-manager/manager-pojo/src/main/java/org/apache/inlong/manager/pojo/util/MySQLSensitiveUrlUtils.java
index 54eadbbbc9..2eb5861c5d 100644
--- 
a/inlong-manager/manager-pojo/src/main/java/org/apache/inlong/manager/pojo/util/MySQLSensitiveUrlUtils.java
+++ 
b/inlong-manager/manager-pojo/src/main/java/org/apache/inlong/manager/pojo/util/MySQLSensitiveUrlUtils.java
@@ -70,15 +70,7 @@ public class MySQLSensitiveUrlUtils {
                 resultUrl = URLDecoder.decode(resultUrl, "UTF-8");
             }
             resultUrl = resultUrl.replaceAll(InlongConstants.REGEX_WHITESPACE, 
InlongConstants.EMPTY);
-
-            String sensitiveKey = containSensitiveKey(resultUrl);
-            while (StringUtils.isNotBlank(sensitiveKey)) {
-                resultUrl = StringUtils.replaceIgnoreCase(resultUrl, 
sensitiveKey + InlongConstants.EQUAL + "true",
-                        InlongConstants.EMPTY);
-                resultUrl = StringUtils.replaceIgnoreCase(resultUrl, 
sensitiveKey + InlongConstants.EQUAL + "yes",
-                        InlongConstants.EMPTY);
-                sensitiveKey = containSensitiveKey(resultUrl);
-            }
+            resultUrl = filterSensitiveKeyByBracket(resultUrl);
             if (resultUrl.contains(InlongConstants.QUESTION_MARK)) {
                 StringBuilder builder = new StringBuilder();
                 builder.append(StringUtils.substringBefore(resultUrl, 
InlongConstants.QUESTION_MARK));
@@ -117,13 +109,45 @@ public class MySQLSensitiveUrlUtils {
         }
     }
 
-    public static String containSensitiveKey(String url) {
-        for (String key : SENSITIVE_REPLACE_PARAM_MAP.keySet()) {
-            if (StringUtils.containsIgnoreCase(url, key + 
InlongConstants.EQUAL + "true")
-                    || StringUtils.containsIgnoreCase(url, key + 
InlongConstants.EQUAL + "yes")) {
-                return key;
+    public static String filterSensitiveKeyByBracket(String url) {
+        if (!StringUtils.containsIgnoreCase(url, InlongConstants.LEFT_BRACKET)
+                || !StringUtils.containsIgnoreCase(url, 
InlongConstants.RIGHT_BRACKET)) {
+            return url;
+        }
+        StringBuilder builder = new StringBuilder();
+        String params;
+        while (StringUtils.containsIgnoreCase(url, 
InlongConstants.LEFT_BRACKET)
+                && StringUtils.containsIgnoreCase(url, 
InlongConstants.RIGHT_BRACKET)) {
+            int preIndex = url.indexOf(InlongConstants.LEFT_BRACKET);
+            int endIndex = url.indexOf(InlongConstants.RIGHT_BRACKET);
+            builder.append(url, 0, preIndex);
+            String temp = url.substring(preIndex + 1, endIndex);
+            List<String> paramList = new ArrayList<>();
+            for (String param : temp.split(InlongConstants.COMMA)) {
+                if (StringUtils.isBlank(param)) {
+                    continue;
+                }
+                String key = StringUtils.substringBefore(param, 
InlongConstants.EQUAL);
+                String value = StringUtils.substringAfter(param, 
InlongConstants.EQUAL);
+                if (SENSITIVE_REMOVE_PARAM_MAP.contains(key) || 
SENSITIVE_REPLACE_PARAM_MAP.containsKey(key)) {
+                    continue;
+                }
+                paramList.add(key + InlongConstants.EQUAL + value);
             }
+            params = StringUtils.join(paramList, InlongConstants.COMMA);
+            builder.append(InlongConstants.LEFT_BRACKET)
+                    .append(params)
+                    .append(InlongConstants.RIGHT_BRACKET);
+            url = url.substring(endIndex + 1);
         }
-        return null;
+        List<String> sensitiveParamList = new ArrayList<>();
+        SENSITIVE_REPLACE_PARAM_MAP
+                .forEach((key, value) -> sensitiveParamList.add(key + 
InlongConstants.EQUAL + value));
+        params = StringUtils.join(sensitiveParamList, InlongConstants.COMMA);
+        builder.append(InlongConstants.LEFT_BRACKET)
+                .append(params)
+                .append(InlongConstants.RIGHT_BRACKET)
+                .append(url);
+        return builder.toString();
     }
 }
diff --git 
a/inlong-manager/manager-pojo/src/test/java/org/apache/inlong/manager/pojo/sink/mysql/MySQLSinkDTOTest.java
 
b/inlong-manager/manager-pojo/src/test/java/org/apache/inlong/manager/pojo/sink/mysql/MySQLSinkDTOTest.java
index cc8ebf2846..fe95104ae5 100644
--- 
a/inlong-manager/manager-pojo/src/test/java/org/apache/inlong/manager/pojo/sink/mysql/MySQLSinkDTOTest.java
+++ 
b/inlong-manager/manager-pojo/src/test/java/org/apache/inlong/manager/pojo/sink/mysql/MySQLSinkDTOTest.java
@@ -33,7 +33,14 @@ public class MySQLSinkDTOTest {
         String originUrl = MySQLSinkDTO.filterSensitive(
                 
"jdbc:mysql://127.0.0.1,(allowLoadLocalInfile=yeſ,allowUrlInLocalInfile=yeſ,allowLoadLocalInfileInPath=.,maxAllowedPacket=655360),:3307/test");
         Assertions.assertEquals(
-                
"jdbc:mysql://127.0.0.1,(,,allowLoadLocalInfileInPath=.,maxAllowedPacket=655360),:3307/test",
+                
"jdbc:mysql://127.0.0.1,(maxAllowedPacket=655360)(autoDeserialize=false,allowUrlInLocalInfile=false,allowLoadLocalInfile=false),:3307/test",
+                originUrl);
+
+        String jdbcUrl =
+                
"jdbc:mysql://127.0.0.1,(allowLoadLocalInfile=%08true,allowUrlInLocalInfile=%08true,allowLoadLocalInfileInPath=.,maxAllowedPacket=655360),:3307/test";
+        originUrl = MySQLSinkDTO.filterSensitive(jdbcUrl);
+        Assertions.assertEquals(
+                
"jdbc:mysql://127.0.0.1,(maxAllowedPacket=655360)(autoDeserialize=false,allowUrlInLocalInfile=false,allowLoadLocalInfile=false),:3307/test",
                 originUrl);
 
         originUrl = MySQLSinkDTO.filterSensitive(
@@ -44,7 +51,9 @@ public class MySQLSinkDTOTest {
 
         originUrl = MySQLSinkDTO.filterSensitive(
                 
"jdbc:mysql://address=(host=127.0.0.1)(port=3306)(allowLoadallowLoadLocalInfile=trueLocalInfile=true)");
-        
Assertions.assertEquals("jdbc:mysql://address=(host=127.0.0.1)(port=3306)()", 
originUrl);
+        Assertions.assertEquals(
+                
"jdbc:mysql://address=(host=127.0.0.1)(port=3306)(allowLoadallowLoadLocalInfile=trueLocalInfile=true)(autoDeserialize=false,allowUrlInLocalInfile=false,allowLoadLocalInfile=false)",
+                originUrl);
 
         originUrl = MySQLSinkDTO.filterSensitive(
                 
"jdbc:mysql://127.0.0.1:3306?autoReconnect=true&autoDeserialize = 
TRue&allowLoadLocalInfile=TRue&allowUrlInLocalInfile=TRue&allowLoadLocalInfileInPath=/");

Reply via email to