Browse Source

SPR-8697 Flag '*/subtype' as illegal.

pull/7/head
Rossen Stoyanchev 13 years ago
parent
commit
01cc76f8e3
  1. 3
      org.springframework.web/src/main/java/org/springframework/http/MediaType.java
  2. 5
      org.springframework.web/src/test/java/org/springframework/http/MediaTypeTests.java

3
org.springframework.web/src/main/java/org/springframework/http/MediaType.java

@ -575,6 +575,9 @@ public class MediaType implements Comparable<MediaType> {
} }
String type = fullType.substring(0, subIndex); String type = fullType.substring(0, subIndex);
String subtype = fullType.substring(subIndex + 1, fullType.length()); String subtype = fullType.substring(subIndex + 1, fullType.length());
if (WILDCARD_TYPE.equals(type) && !WILDCARD_TYPE.equals(subtype)) {
throw new IllegalArgumentException("A wildcard type is legal only in '*/*' (all media types).");
}
Map<String, String> parameters = null; Map<String, String> parameters = null;
if (parts.length > 1) { if (parts.length > 1) {

5
org.springframework.web/src/test/java/org/springframework/http/MediaTypeTests.java

@ -128,6 +128,11 @@ public class MediaTypeTests {
MediaType.parseMediaType("audio/"); MediaType.parseMediaType("audio/");
} }
@Test(expected = IllegalArgumentException.class)
public void parseMediaTypeTypeRange() {
MediaType.parseMediaType("*/json");
}
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void parseMediaTypeIllegalType() { public void parseMediaTypeIllegalType() {
MediaType.parseMediaType("audio(/basic"); MediaType.parseMediaType("audio(/basic");

Loading…
Cancel
Save