diff --git a/docs/monasca-api-spec.md b/docs/monasca-api-spec.md index fce1acfb9..65acfe383 100644 --- a/docs/monasca-api-spec.md +++ b/docs/monasca-api-spec.md @@ -331,10 +331,10 @@ Before using the API, you must first get a valid auth token from Keystone. All A A metric is uniquely identified by a name and set of dimensions. ### Name -Defines the name of a metric. A name is of type string(255). The name may include any characters except the following: `> < = { } ( ) , ' " ; &`. If one of the restricted characters is needed, this can be achieved by double quoting the name. +Defines the name of a metric. A name is of type string(255). The name may include any characters except the following: `> < = { } ( ) , ' " \ ; &`. A metric name surrounded by double quotes may include the following: `> < = { } ( ) , ; &`, but not `" \`. Note that JSON does allow control characters (such as `\n`), however these should not be used in metric names. ### Dimensions -A dictionary of (key, value) pairs. The key and value are of type string(255). Dimension keys may not begin with '_' (underscore). The dimensions string may include any characters except the following: `> < = { } ( ) , ' " ; &`. If one of the restricted characters is needed, this can be achieved by double quoting the dimension key or value containing the character. +A dictionary of (key, value) pairs. The key and value are of type string(255). Dimension keys may not begin with '_' (underscore). The dimension key and value strings may include any characters except the following: `> < = { } ( ) , ' " \ ; &`. A dimension key or value surrounded by double quotes may include the following: `> < = { } ( ) , ; &`, but not `" \`. Note that JSON does allow control characters (such as `\n`), however these should not be used in dimension keys or values. ### Text Representation In this document, metrics will be represented in the form `name{name=value,name=value}` where name is the metric name and the name=value pairs in the curly braces are the dimensions. For example, `cpu.idle_perc{service=monitoring,hostname=mini-mon}` represents a metric with the name "cpu.idle_perc" and the dimensions "service=monitoring" and "hostname=mini-mon". diff --git a/java/src/main/java/monasca/api/app/validation/DimensionValidation.java b/java/src/main/java/monasca/api/app/validation/DimensionValidation.java index ac2c2c575..34899d8e9 100644 --- a/java/src/main/java/monasca/api/app/validation/DimensionValidation.java +++ b/java/src/main/java/monasca/api/app/validation/DimensionValidation.java @@ -34,8 +34,8 @@ public final class DimensionValidation { private static final Map VALIDATORS; private static final Pattern UUID_PATTERN = Pattern .compile("\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12}"); - private static final Pattern VALID_DIMENSION_NAME = Pattern.compile("[^><={}(), '\";&]+$"); - private static final String INVALID_CHAR_STRING = "> < = { } ( ) ' \" , ; &"; + private static final Pattern VALID_DIMENSION_NAME = Pattern.compile("[^><={}(), '\"\\\\;&]+$"); + private static final String INVALID_CHAR_STRING = "> < = { } ( ) ' \" \\ , ; &"; private DimensionValidation() {} diff --git a/java/src/main/java/monasca/api/app/validation/MetricNameValidation.java b/java/src/main/java/monasca/api/app/validation/MetricNameValidation.java index c091c5c4a..cbdd54d39 100644 --- a/java/src/main/java/monasca/api/app/validation/MetricNameValidation.java +++ b/java/src/main/java/monasca/api/app/validation/MetricNameValidation.java @@ -28,7 +28,7 @@ import com.sun.jersey.spi.container.WebApplication; * Utilities for validating metric names. */ public class MetricNameValidation { - private static final Pattern VALID_METRIC_NAME = Pattern.compile("[^><={}(), '\";&]+$"); + private static final Pattern VALID_METRIC_NAME = Pattern.compile("[^><={}(), '\"\\\\;&]+$"); private MetricNameValidation() {} @@ -60,7 +60,7 @@ public class MetricNameValidation { throw Exceptions.unprocessableEntity("Metric name %s must be %d characters or less", metricName, CreateMetricCommand.MAX_NAME_LENGTH); if (!Services.isReserved(metricName) && !VALID_METRIC_NAME.matcher(metricName).matches()) - throw Exceptions.unprocessableEntity("Metric name %s may not contain: > < = { } ( ) ' \" , ; &", + throw Exceptions.unprocessableEntity("Metric name %s may not contain: > < = { } ( ) ' \" \\ , ; &", metricName); // Service specific validations diff --git a/java/src/test/java/monasca/api/resource/MetricResourceTest.java b/java/src/test/java/monasca/api/resource/MetricResourceTest.java index 92714daf1..a64273049 100644 --- a/java/src/test/java/monasca/api/resource/MetricResourceTest.java +++ b/java/src/test/java/monasca/api/resource/MetricResourceTest.java @@ -165,7 +165,7 @@ public class MetricResourceTest extends AbstractMonApiResourceTest { valueMeta)); ErrorMessages.assertThat(response.getEntity(String.class)).matches("unprocessable_entity", 422, - "Metric name hpcs{.compute% may not contain: > < = { } ( ) ' \" , ; &"); + "Metric name hpcs{.compute% may not contain: > < = { } ( ) ' \" \\ , ; &"); } public void shouldErrorOnCreateWithTooLongName() {