Skip to content

Commit f46295f

Browse files
fix:fix api match when using IN or NOT_IN. (#569)
1 parent 5b79f39 commit f46295f

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

polaris-common/polaris-model/src/main/java/com/tencent/polaris/api/utils/RuleUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public static boolean matchStringValue(MatchStringType matchType, String actualV
112112
String[] tokens = matchValue.split(",");
113113
for (String token : tokens) {
114114
if (useTrieNode && trieNodeFunction != null) {
115-
if (TrieUtil.checkSimpleApi(trieNodeFunction.apply(matchValue), actualValue)) {
115+
if (TrieUtil.checkSimpleApi(trieNodeFunction.apply(token), actualValue)) {
116116
return true;
117117
}
118118
} else {
@@ -127,7 +127,7 @@ public static boolean matchStringValue(MatchStringType matchType, String actualV
127127
String[] tokens = matchValue.split(",");
128128
for (String token : tokens) {
129129
if (useTrieNode && trieNodeFunction != null) {
130-
if (TrieUtil.checkSimpleApi(trieNodeFunction.apply(matchValue), actualValue)) {
130+
if (TrieUtil.checkSimpleApi(trieNodeFunction.apply(token), actualValue)) {
131131
return false;
132132
}
133133
} else {

polaris-common/polaris-model/src/test/java/com/tencent/polaris/api/utils/RuleUtilsTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,16 @@ public void testMatchMetadata() {
107107
assertThat(matchMetadata(ruleMeta3, destMeta3)).isTrue();
108108
}
109109

110+
@Test
111+
public void testInMatch() {
112+
assertThat(matchStringValue(ModelProto.MatchString.MatchStringType.IN, "123", "123,456")).isTrue();
113+
assertThat(matchStringValue(ModelProto.MatchString.MatchStringType.IN, "123", "456,123")).isTrue();
114+
assertThat(matchStringValue(ModelProto.MatchString.MatchStringType.IN, "231", "123,456")).isFalse();
115+
assertThat(matchStringValue(ModelProto.MatchString.MatchStringType.NOT_IN, "123", "123,456")).isFalse();
116+
assertThat(matchStringValue(ModelProto.MatchString.MatchStringType.NOT_IN, "123", "456,123")).isFalse();
117+
assertThat(matchStringValue(ModelProto.MatchString.MatchStringType.NOT_IN, "231", "123,456")).isTrue();
118+
}
119+
110120
@Test
111121
public void testRangeMatch() {
112122
assertThat(matchStringValue(ModelProto.MatchString.MatchStringType.RANGE, "123", "123~456")).isTrue();

0 commit comments

Comments
 (0)