Skip to content

Commit 38f3305

Browse files
committed
fix: escape ':' character in FilterType JSON conditions to prevent query parsing issues
1 parent 3348d88 commit 38f3305

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

backend/src/main/java/com/park/utmstack/domain/UtmAlertTagRule.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
import com.fasterxml.jackson.annotation.JsonIgnore;
55
import com.fasterxml.jackson.core.JsonProcessingException;
66
import com.fasterxml.jackson.core.type.TypeReference;
7-
import com.fasterxml.jackson.databind.JsonNode;
87
import com.fasterxml.jackson.databind.ObjectMapper;
9-
import com.fasterxml.jackson.databind.node.ObjectNode;
108
import com.park.utmstack.domain.chart_builder.types.query.FilterType;
119
import com.park.utmstack.web.rest.vm.AlertTagRuleVM;
1210
import org.springframework.util.StringUtils;
@@ -149,16 +147,8 @@ public void setRuleAppliedTags(String ruleAppliedTags) {
149147
public List<FilterType> getConditions() throws JsonProcessingException {
150148
if (StringUtils.hasText(ruleConditions)) {
151149
ObjectMapper om = new ObjectMapper();
152-
153-
JsonNode rootNode = om.readTree(ruleConditions);
154-
155-
rootNode.forEach(node -> {
156-
JsonNode valueNode = node.get("value");
157-
if (valueNode != null && valueNode.asText().contains(":")) {
158-
((ObjectNode) node).put("value", valueNode.asText().replace(":", "\\:"));
159-
}
150+
conditions = om.readValue(ruleConditions, new TypeReference<>() {
160151
});
161-
conditions = om.convertValue(rootNode, new TypeReference<>() {});
162152
}
163153
return conditions;
164154
}

backend/src/main/java/com/park/utmstack/service/elasticsearch/SearchUtil.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,9 @@ private static void buildContainOperator(BoolQuery.Builder bool, FilterType filt
127127
final String ctx = CLASSNAME + ".buildContainOperator";
128128
try {
129129
filter.validate();
130+
String value = CustomStringEscapeUtil.openSearchQueryStringEscap(String.valueOf(filter.getValue()));
130131
bool.filter(f -> f.queryString(s -> s.fields(filter.getField())
131-
.query("*" + filter.getValue() + "*")
132+
.query("*" + value + "*")
132133
.defaultOperator(Operator.And)
133134
.lenient(true)
134135
.type(TextQueryType.BestFields)));
@@ -141,8 +142,9 @@ private static void buildDoesNotContainOperator(BoolQuery.Builder bool, FilterTy
141142
final String ctx = CLASSNAME + ".buildDoesNotContainOperator";
142143
try {
143144
filter.validate();
145+
String value = CustomStringEscapeUtil.openSearchQueryStringEscap(String.valueOf(filter.getValue()));
144146
bool.mustNot(n -> n.queryString(s -> s.fields(filter.getField())
145-
.query("*" + filter.getValue() + "*")
147+
.query("*" + value + "*")
146148
.defaultOperator(Operator.And)
147149
.lenient(true)
148150
.type(TextQueryType.BestFields)));

0 commit comments

Comments
 (0)