diff --git a/org.springframework.web/src/main/java/org/springframework/http/MediaType.java b/org.springframework.web/src/main/java/org/springframework/http/MediaType.java index fa7886216a..8879156a3a 100644 --- a/org.springframework.web/src/main/java/org/springframework/http/MediaType.java +++ b/org.springframework.web/src/main/java/org/springframework/http/MediaType.java @@ -575,6 +575,9 @@ public class MediaType implements Comparable { } String type = fullType.substring(0, subIndex); 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 parameters = null; if (parts.length > 1) { diff --git a/org.springframework.web/src/test/java/org/springframework/http/MediaTypeTests.java b/org.springframework.web/src/test/java/org/springframework/http/MediaTypeTests.java index 950b0114b4..e2c6f68c04 100644 --- a/org.springframework.web/src/test/java/org/springframework/http/MediaTypeTests.java +++ b/org.springframework.web/src/test/java/org/springframework/http/MediaTypeTests.java @@ -128,6 +128,11 @@ public class MediaTypeTests { MediaType.parseMediaType("audio/"); } + @Test(expected = IllegalArgumentException.class) + public void parseMediaTypeTypeRange() { + MediaType.parseMediaType("*/json"); + } + @Test(expected = IllegalArgumentException.class) public void parseMediaTypeIllegalType() { MediaType.parseMediaType("audio(/basic");