diff --git a/polaris-common/polaris-model/src/main/java/com/tencent/polaris/api/utils/RuleUtils.java b/polaris-common/polaris-model/src/main/java/com/tencent/polaris/api/utils/RuleUtils.java index 501df36c5..13e40dafc 100644 --- a/polaris-common/polaris-model/src/main/java/com/tencent/polaris/api/utils/RuleUtils.java +++ b/polaris-common/polaris-model/src/main/java/com/tencent/polaris/api/utils/RuleUtils.java @@ -112,7 +112,7 @@ public static boolean matchStringValue(MatchStringType matchType, String actualV String[] tokens = matchValue.split(","); for (String token : tokens) { if (useTrieNode && trieNodeFunction != null) { - if (TrieUtil.checkSimpleApi(trieNodeFunction.apply(matchValue), actualValue)) { + if (TrieUtil.checkSimpleApi(trieNodeFunction.apply(token), actualValue)) { return true; } } else { @@ -127,7 +127,7 @@ public static boolean matchStringValue(MatchStringType matchType, String actualV String[] tokens = matchValue.split(","); for (String token : tokens) { if (useTrieNode && trieNodeFunction != null) { - if (TrieUtil.checkSimpleApi(trieNodeFunction.apply(matchValue), actualValue)) { + if (TrieUtil.checkSimpleApi(trieNodeFunction.apply(token), actualValue)) { return false; } } else { diff --git a/polaris-common/polaris-model/src/test/java/com/tencent/polaris/api/utils/RuleUtilsTest.java b/polaris-common/polaris-model/src/test/java/com/tencent/polaris/api/utils/RuleUtilsTest.java index 6d8062aa2..8dafda7d0 100644 --- a/polaris-common/polaris-model/src/test/java/com/tencent/polaris/api/utils/RuleUtilsTest.java +++ b/polaris-common/polaris-model/src/test/java/com/tencent/polaris/api/utils/RuleUtilsTest.java @@ -107,6 +107,16 @@ public void testMatchMetadata() { assertThat(matchMetadata(ruleMeta3, destMeta3)).isTrue(); } + @Test + public void testInMatch() { + assertThat(matchStringValue(ModelProto.MatchString.MatchStringType.IN, "123", "123,456")).isTrue(); + assertThat(matchStringValue(ModelProto.MatchString.MatchStringType.IN, "123", "456,123")).isTrue(); + assertThat(matchStringValue(ModelProto.MatchString.MatchStringType.IN, "231", "123,456")).isFalse(); + assertThat(matchStringValue(ModelProto.MatchString.MatchStringType.NOT_IN, "123", "123,456")).isFalse(); + assertThat(matchStringValue(ModelProto.MatchString.MatchStringType.NOT_IN, "123", "456,123")).isFalse(); + assertThat(matchStringValue(ModelProto.MatchString.MatchStringType.NOT_IN, "231", "123,456")).isTrue(); + } + @Test public void testRangeMatch() { assertThat(matchStringValue(ModelProto.MatchString.MatchStringType.RANGE, "123", "123~456")).isTrue();