diff options
3 files changed, 15 insertions, 2 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/es/EsUtils.java b/server/sonar-server/src/main/java/org/sonar/server/es/EsUtils.java index 85f65400722..539fd2b3422 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/es/EsUtils.java +++ b/server/sonar-server/src/main/java/org/sonar/server/es/EsUtils.java @@ -48,7 +48,11 @@ import static java.lang.String.format; public class EsUtils { public static final int SCROLL_TIME_IN_MINUTES = 3; - private static final Pattern SPECIAL_REGEX_CHARS = Pattern.compile("[{}()\\[\\].+*?^$\\\\|]"); + + /** + * See https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-regexp-query.html + */ + private static final Pattern SPECIAL_REGEX_CHARS = Pattern.compile("[#@&~<>\"{}()\\[\\].+*?^$\\\\|]"); private EsUtils() { // only static methods diff --git a/server/sonar-server/src/test/java/org/sonar/server/es/EsUtilsTest.java b/server/sonar-server/src/test/java/org/sonar/server/es/EsUtilsTest.java index 95d81be899c..12e4102adb9 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/es/EsUtilsTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/es/EsUtilsTest.java @@ -88,6 +88,14 @@ public class EsUtilsTest { assertThat(escapeSpecialRegexChars("^")).isEqualTo("\\^"); assertThat(escapeSpecialRegexChars("$")).isEqualTo("\\$"); assertThat(escapeSpecialRegexChars("|")).isEqualTo("\\|"); - assertThat(escapeSpecialRegexChars("a bit of | $ .* ^ everything")).isEqualTo("a bit of \\| \\$ \\.\\* \\^ everything"); + assertThat(escapeSpecialRegexChars("<")).isEqualTo("\\<"); + assertThat(escapeSpecialRegexChars(">")).isEqualTo("\\>"); + assertThat(escapeSpecialRegexChars("\"")).isEqualTo("\\\""); + assertThat(escapeSpecialRegexChars("#")).isEqualTo("\\#"); + assertThat(escapeSpecialRegexChars("~")).isEqualTo("\\~"); + assertThat(escapeSpecialRegexChars("$")).isEqualTo("\\$"); + assertThat(escapeSpecialRegexChars("&")).isEqualTo("\\&"); + assertThat(escapeSpecialRegexChars("?")).isEqualTo("\\?"); + assertThat(escapeSpecialRegexChars("a bit of | & #<\"$ .* ^ everything")).isEqualTo("a bit of \\| \\& \\#\\<\\\"\\$ \\.\\* \\^ everything"); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/RuleServiceMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/RuleServiceMediumTest.java index 80440da8f90..2e913fdd7ee 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/RuleServiceMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/RuleServiceMediumTest.java @@ -108,6 +108,7 @@ public class RuleServiceMediumTest { assertThat(service.listTags("mis[", 10)).isEmpty(); assertThat(service.listTags("mis\\d", 10)).isEmpty(); assertThat(service.listTags(".*", 10)).isEmpty(); + assertThat(service.listTags("<foo>", 10)).isEmpty(); } @Test |