abbreviations are not allowed in Accept header
Change-Id: Ib0250e649af086359292deaa305defb3a660e5c5 Signed-off-by: Christian Amend <chrisam@apache.org>
This commit is contained in:
parent
0eb95ed72b
commit
bd4ad859a6
|
@ -103,10 +103,7 @@ public class AcceptType {
|
|||
final String params = (typesAndParameters.length > 1 ? typesAndParameters[1] : null);
|
||||
|
||||
String[] tokens = types.split(TypeUtil.TYPE_SUBTYPE_SEPARATOR);
|
||||
if (tokens.length == 1) {
|
||||
typeSubtype.add(tokens[0]);
|
||||
typeSubtype.add(TypeUtil.MEDIA_TYPE_WILDCARD);
|
||||
} else if (tokens.length == 2) {
|
||||
if (tokens.length == 2) {
|
||||
if (tokens[0] == null || tokens[0].isEmpty()) {
|
||||
throw new IllegalArgumentException("No type found in format '" + format + "'.");
|
||||
} else if (tokens[1] == null || tokens[1].isEmpty()) {
|
||||
|
@ -116,8 +113,8 @@ public class AcceptType {
|
|||
typeSubtype.add(tokens[1]);
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("Too many '" + TypeUtil.TYPE_SUBTYPE_SEPARATOR + "' in format '" + format
|
||||
+ "'.");
|
||||
throw new IllegalArgumentException("Not exactly one '" + TypeUtil.TYPE_SUBTYPE_SEPARATOR +
|
||||
"' in format '" + format + "', or it is at the beginning or at the end.");
|
||||
}
|
||||
|
||||
TypeUtil.parseParameters(params, parameters);
|
||||
|
|
|
@ -38,8 +38,6 @@ public class AcceptTypeTest {
|
|||
|
||||
assertTrue(atl.get(0).matches(ContentType.create("a/a")));
|
||||
assertTrue(atl.get(0).matches(ContentType.create("b/b")));
|
||||
|
||||
assertEquals("*/*", AcceptType.create("*").get(0).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -112,6 +110,11 @@ public class AcceptTypeTest {
|
|||
assertEquals("application/json;q=0.2", atl.get(0).toString());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void abbreviationsNotAllowed() {
|
||||
AcceptType.create("application");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testWrongQParameter() {
|
||||
AcceptType.create(" a/a;q=z ");
|
||||
|
|
Loading…
Reference in New Issue