aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2016-11-30 17:35:11 +0100
committerSimon Brandhof <simon.brandhof@sonarsource.com>2016-11-30 17:35:11 +0100
commit6cff54209509a9640dc6d0409a718c2d655c2950 (patch)
tree5b3fd532d4a44d8da8de1e864b2266fddbcf580c
parent5eedd7e06021b78f49522f3d296bc9cd3939c415 (diff)
downloadsonarqube-6cff54209509a9640dc6d0409a718c2d655c2950.tar.gz
sonarqube-6cff54209509a9640dc6d0409a718c2d655c2950.zip
SONAR-8437 add missing characters to be escaped
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/es/EsUtils.java6
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/es/EsUtilsTest.java10
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/rule/RuleServiceMediumTest.java1
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