diff options
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/rule/RuleTagFormat.java | 6 | ||||
-rw-r--r-- | sonar-plugin-api/src/test/java/org/sonar/api/rule/RuleTagFormatTest.java | 6 |
2 files changed, 11 insertions, 1 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rule/RuleTagFormat.java b/sonar-plugin-api/src/main/java/org/sonar/api/rule/RuleTagFormat.java index 68bdf27c0b4..998a31950d8 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/rule/RuleTagFormat.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/rule/RuleTagFormat.java @@ -26,12 +26,16 @@ import org.apache.commons.lang.StringUtils; */ public class RuleTagFormat { + // Allowed characters are the same as those on StackOverflow + // see http://meta.stackoverflow.com/questions/22624/what-symbols-characters-are-not-allowed-in-tags + private static final String VALID_CHARACTERS_REGEX = "^[a-z0-9\\+#\\-\\.]+$"; + private RuleTagFormat() { // only static methods } public static boolean isValid(String tag) { - return StringUtils.isNotBlank(tag) && StringUtils.indexOf(tag, " ") < 0; + return StringUtils.isNotBlank(tag) && tag.matches(VALID_CHARACTERS_REGEX); } public static void validate(String tag) { diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/rule/RuleTagFormatTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/rule/RuleTagFormatTest.java index c4b9263588c..3197d4eca16 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/rule/RuleTagFormatTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/rule/RuleTagFormatTest.java @@ -31,8 +31,14 @@ public class RuleTagFormatTest { assertThat(RuleTagFormat.isValid("")).isFalse(); assertThat(RuleTagFormat.isValid(" ")).isFalse(); assertThat(RuleTagFormat.isValid("coding style")).isFalse(); + assertThat(RuleTagFormat.isValid("Style")).isFalse(); + assertThat(RuleTagFormat.isValid("sTyle")).isFalse(); + assertThat(RuleTagFormat.isValid("@style")).isFalse(); assertThat(RuleTagFormat.isValid("style")).isTrue(); + assertThat(RuleTagFormat.isValid("c++")).isTrue(); + assertThat(RuleTagFormat.isValid("f#")).isTrue(); + assertThat(RuleTagFormat.isValid("c++11")).isTrue(); } @Test |