aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2015-07-23 15:35:20 +0200
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2015-07-24 09:22:45 +0200
commit2a5d7c1a948efa94203a93592c8137b63fc4757b (patch)
tree4b1315a1811b209c41809ad7b891d37150df4e35 /server
parent78222b3162dc9c35828fc18bb3f68611ea646e43 (diff)
downloadsonarqube-2a5d7c1a948efa94203a93592c8137b63fc4757b.tar.gz
sonarqube-2a5d7c1a948efa94203a93592c8137b63fc4757b.zip
SONAR-6571 update the metric key validation without dots nor semi-colon
Diffstat (limited to 'server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/util/MetricKeyValidator.java10
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/metric/ws/CreateActionTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/util/MetricKeyValidatorTest.java8
3 files changed, 10 insertions, 10 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/util/MetricKeyValidator.java b/server/sonar-server/src/main/java/org/sonar/server/util/MetricKeyValidator.java
index d077cf42cc7..7f3d77412b7 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/util/MetricKeyValidator.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/util/MetricKeyValidator.java
@@ -27,9 +27,9 @@ public class MetricKeyValidator {
}
/*
- * Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit
+ * Allowed characters are alphanumeric, '-', '_', with at least one non-digit
*/
- private static final String VALID_MODULE_KEY_REGEXP = "[\\p{Alnum}\\-_.:]*[\\p{Alpha}\\-_.:]+[\\p{Alnum}\\-_.:]*";
+ private static final String VALID_METRIC_KEY_REGEXP = "[\\p{Alnum}\\-_]*[\\p{Alpha}\\-_]+[\\p{Alnum}\\-_]*";
/**
* <p>Test if given parameter is valid for a project/module. Valid format is:</p>
@@ -39,7 +39,7 @@ public class MetricKeyValidator {
* <li>Uppercase ASCII letters A-Z</li>
* <li>Lowercase ASCII letters a-z</li>
* <li>ASCII digits 0-9</li>
- * <li>Punctuation signs dash '-', underscore '_', period '.' and colon ':'</li>
+ * <li>Punctuation signs dash '-', underscore '_'</li>
* </ul>
* </li>
* <li>At least one non-digit</li>
@@ -48,12 +48,12 @@ public class MetricKeyValidator {
* @return <code>true</code> if <code>candidateKey</code> can be used for a metric
*/
public static boolean isMetricKeyValid(String candidateKey) {
- return candidateKey.matches(VALID_MODULE_KEY_REGEXP);
+ return candidateKey.matches(VALID_METRIC_KEY_REGEXP);
}
public static String checkMetricKeyFormat(String candidateKey) {
if (!isMetricKeyValid(candidateKey)) {
- throw new IllegalArgumentException(String.format("Malformed metric key '%s'. Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit.",
+ throw new IllegalArgumentException(String.format("Malformed metric key '%s'. Allowed characters are alphanumeric, '-', '_', with at least one non-digit.",
candidateKey));
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/metric/ws/CreateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/metric/ws/CreateActionTest.java
index 4d1d6833ff0..d844cdd171a 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/metric/ws/CreateActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/metric/ws/CreateActionTest.java
@@ -261,7 +261,7 @@ public class CreateActionTest {
expectedException.expect(IllegalArgumentException.class);
newRequest()
- .setParam(PARAM_KEY, "(123:456)")
+ .setParam(PARAM_KEY, "123:456")
.setParam(PARAM_NAME, DEFAULT_NAME)
.setParam(PARAM_TYPE, DEFAULT_TYPE)
.execute();
diff --git a/server/sonar-server/src/test/java/org/sonar/server/util/MetricKeyValidatorTest.java b/server/sonar-server/src/test/java/org/sonar/server/util/MetricKeyValidatorTest.java
index c2ca240a249..d835fd69d73 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/util/MetricKeyValidatorTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/util/MetricKeyValidatorTest.java
@@ -34,16 +34,16 @@ public class MetricKeyValidatorTest {
@Test
public void isMetricKeyValid() {
assertThat(MetricKeyValidator.isMetricKeyValid("")).isFalse();
- assertThat(MetricKeyValidator.isMetricKeyValid("1.2.3:ABC-1.2.3")).isTrue();
- assertThat(MetricKeyValidator.isMetricKeyValid("123.321")).isTrue();
+ assertThat(MetricKeyValidator.isMetricKeyValid("1_2_3-ABC-1_2_3")).isTrue();
+ assertThat(MetricKeyValidator.isMetricKeyValid("123_321")).isTrue();
assertThat(MetricKeyValidator.isMetricKeyValid("123456")).isFalse();
- assertThat(MetricKeyValidator.isMetricKeyValid("(123.A.321)")).isFalse();
+ assertThat(MetricKeyValidator.isMetricKeyValid("1.2.3_A_3:2:1")).isFalse();
}
@Test
public void checkMetricKeyFormat() {
expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Malformed metric key '123456'. Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit.");
+ expectedException.expectMessage("Malformed metric key '123456'. Allowed characters are alphanumeric, '-', '_', with at least one non-digit.");
MetricKeyValidator.checkMetricKeyFormat("123456");
}