From 01cc76f8e3b3016677cad5d7be8a45ee1f6bab2c Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Thu, 17 Nov 2011 20:15:49 +0000 Subject: [PATCH] SPR-8697 Flag '*/subtype' as illegal. --- .../src/main/java/org/springframework/http/MediaType.java | 3 +++ .../test/java/org/springframework/http/MediaTypeTests.java | 5 +++++ 2 files changed, 8 insertions(+) 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");