Skip to content

Commit 5198360

Browse files
remove unnecessary conditional statement, add test case
1 parent 9592090 commit 5198360

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

src/main/java/com/joonsang/graylog/GraylogQuery.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,7 @@ private String escape(String input) {
393393
};
394394

395395
for (String meta: metaCharacters) {
396-
if (input.contains(meta)) {
397-
input = input.replace(meta, "\\" + meta);
398-
}
396+
input = input.replace(meta, "\\" + meta);
399397
}
400398

401399
return input;

src/test/java/com/joonsang/graylog/GraylogQueryTests.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,4 +256,18 @@ public void TC_019_APPEND() {
256256
.as("TC_019_APPEND")
257257
.isEqualTo(expect);
258258
}
259+
260+
@Test
261+
public void TC_020_ESCAPING() {
262+
GraylogQuery query = GraylogQuery.builder()
263+
.field("content_type", "application/json")
264+
.and()
265+
.field("response_body", "{\"nickname\": \"[*test] John Doe\", \"message\": \"hello?\"}");
266+
267+
String expect = "content_type:\"application\\/json\" AND response_body:\"\\{\\\"nickname\\\"\\\\: \\\"\\[\\*test\\] John Doe\\\", \\\"message\\\"\\\\: \\\"hello\\?\\\"\\}\"";
268+
269+
assertThat(query.build())
270+
.as("TC_020_SANITIZE")
271+
.isEqualTo(expect);
272+
}
259273
}

0 commit comments

Comments
 (0)