You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ji...@apache.org on 2023/06/26 16:41:56 UTC

[shardingsphere] branch master updated: Remove Pattern.CASE_INSENSITIVE with RuleRootNodePath (#26594)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new c4369dcb18f Remove Pattern.CASE_INSENSITIVE with RuleRootNodePath (#26594)
c4369dcb18f is described below

commit c4369dcb18f27a64f638da9421098c4d3bf0334b
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Tue Jun 27 00:41:49 2023 +0800

    Remove Pattern.CASE_INSENSITIVE with RuleRootNodePath (#26594)
    
    * Remove Pattern.CASE_INSENSITIVE with RuleRootNodePath
    
    * Simplify reg
---
 .../infra/metadata/nodepath/RuleRootNodePath.java              |  4 ++--
 .../infra/metadata/nodepath/item/NamedRuleItemNodePath.java    | 10 +++++-----
 .../infra/metadata/nodepath/item/UniqueRuleItemNodePath.java   |  8 ++++----
 .../infra/metadata/nodepath/RuleRootNodePathTest.java          |  2 +-
 4 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/nodepath/RuleRootNodePath.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/nodepath/RuleRootNodePath.java
index 7e8e610f87b..b9392be79cd 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/nodepath/RuleRootNodePath.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/nodepath/RuleRootNodePath.java
@@ -26,7 +26,7 @@ import java.util.regex.Pattern;
  */
 public final class RuleRootNodePath {
     
-    private static final String RULE_NODE_PREFIX = "/([\\w\\-]+)/([\\w\\-]+)/rules/";
+    private static final String RULE_NODE_PREFIX = "/[\\w\\-]+/[\\w\\-]+/rules/";
     
     @Getter
     private final String nodePrefix;
@@ -35,7 +35,7 @@ public final class RuleRootNodePath {
     
     public RuleRootNodePath(final String ruleType) {
         nodePrefix = RULE_NODE_PREFIX + ruleType;
-        pathPattern = Pattern.compile(nodePrefix + "/.*", Pattern.CASE_INSENSITIVE);
+        pathPattern = Pattern.compile(nodePrefix + "/.*");
     }
     
     /**
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/nodepath/item/NamedRuleItemNodePath.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/nodepath/item/NamedRuleItemNodePath.java
index 14f7ea2825e..e203baae2c9 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/nodepath/item/NamedRuleItemNodePath.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/nodepath/item/NamedRuleItemNodePath.java
@@ -42,9 +42,9 @@ public final class NamedRuleItemNodePath {
     
     public NamedRuleItemNodePath(final RuleRootNodePath rootNodePath, final String type) {
         this.type = type;
-        pathPattern = Pattern.compile(rootNodePath.getNodePrefix() + "/" + type + "/.*", Pattern.CASE_INSENSITIVE);
-        namePathPattern = Pattern.compile(rootNodePath.getNodePrefix() + "/" + type + NAME, Pattern.CASE_INSENSITIVE);
-        activeVersionPathPattern = Pattern.compile(rootNodePath.getNodePrefix() + "/" + type + ACTIVE_VERSION, Pattern.CASE_INSENSITIVE);
+        pathPattern = Pattern.compile(rootNodePath.getNodePrefix() + "/" + type + "/.*");
+        namePathPattern = Pattern.compile(rootNodePath.getNodePrefix() + "/" + type + NAME);
+        activeVersionPathPattern = Pattern.compile(rootNodePath.getNodePrefix() + "/" + type + ACTIVE_VERSION);
     }
     
     /**
@@ -75,7 +75,7 @@ public final class NamedRuleItemNodePath {
      */
     public Optional<String> getName(final String path) {
         Matcher matcher = namePathPattern.matcher(path);
-        return matcher.find() ? Optional.of(matcher.group(3)) : Optional.empty();
+        return matcher.find() ? Optional.of(matcher.group(1)) : Optional.empty();
     }
     
     /**
@@ -86,6 +86,6 @@ public final class NamedRuleItemNodePath {
      */
     public Optional<String> getNameByActiveVersion(final String path) {
         Matcher matcher = activeVersionPathPattern.matcher(path);
-        return matcher.find() ? Optional.of(matcher.group(3)) : Optional.empty();
+        return matcher.find() ? Optional.of(matcher.group(1)) : Optional.empty();
     }
 }
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/nodepath/item/UniqueRuleItemNodePath.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/nodepath/item/UniqueRuleItemNodePath.java
index e310815c0db..8045e1a17a0 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/nodepath/item/UniqueRuleItemNodePath.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/nodepath/item/UniqueRuleItemNodePath.java
@@ -42,15 +42,15 @@ public final class UniqueRuleItemNodePath {
     public UniqueRuleItemNodePath(final RuleRootNodePath ruleRootNodePath, final String type) {
         parentNode = null;
         this.type = type;
-        pathPattern = Pattern.compile(ruleRootNodePath.getNodePrefix() + "/" + type + VERSIONS, Pattern.CASE_INSENSITIVE);
-        activeVersionPathPattern = Pattern.compile(ruleRootNodePath.getNodePrefix() + "/" + type + ACTIVE_VERSION, Pattern.CASE_INSENSITIVE);
+        pathPattern = Pattern.compile(ruleRootNodePath.getNodePrefix() + "/" + type + VERSIONS);
+        activeVersionPathPattern = Pattern.compile(ruleRootNodePath.getNodePrefix() + "/" + type + ACTIVE_VERSION);
     }
     
     public UniqueRuleItemNodePath(final RuleRootNodePath ruleRootNodePath, final String parentNode, final String type) {
         this.parentNode = parentNode;
         this.type = type;
-        pathPattern = Pattern.compile(ruleRootNodePath.getNodePrefix() + "/" + parentNode + "/" + type + VERSIONS, Pattern.CASE_INSENSITIVE);
-        activeVersionPathPattern = Pattern.compile(ruleRootNodePath.getNodePrefix() + "/" + parentNode + "/" + type + ACTIVE_VERSION, Pattern.CASE_INSENSITIVE);
+        pathPattern = Pattern.compile(ruleRootNodePath.getNodePrefix() + "/" + parentNode + "/" + type + VERSIONS);
+        activeVersionPathPattern = Pattern.compile(ruleRootNodePath.getNodePrefix() + "/" + parentNode + "/" + type + ACTIVE_VERSION);
     }
     
     /**
diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/nodepath/RuleRootNodePathTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/nodepath/RuleRootNodePathTest.java
index 5c3b6f5c5b4..6b5789d15b1 100644
--- a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/nodepath/RuleRootNodePathTest.java
+++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/nodepath/RuleRootNodePathTest.java
@@ -30,7 +30,7 @@ class RuleRootNodePathTest {
     
     @Test
     void assertGetRuleNodePrefix() {
-        assertThat(nodePath.getNodePrefix(), is("/([\\w\\-]+)/([\\w\\-]+)/rules/foo"));
+        assertThat(nodePath.getNodePrefix(), is("/[\\w\\-]+/[\\w\\-]+/rules/foo"));
     }
     
     @Test