Skip to content

Commit 6316a45

Browse files
committed
backported fix for SPR-8697 from 3.1 RC2
1 parent e298c20 commit 6316a45

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,6 @@ else if (this.type.equals(other.type)) {
404404
int otherPlusIdx = other.subtype.indexOf('+');
405405
if (thisPlusIdx != -1 && otherPlusIdx != -1) {
406406
String thisSubtypeNoSuffix = this.subtype.substring(0, thisPlusIdx);
407-
408407
String thisSubtypeSuffix = this.subtype.substring(thisPlusIdx + 1);
409408
String otherSubtypeSuffix = other.subtype.substring(otherPlusIdx + 1);
410409
if (thisSubtypeSuffix.equals(otherSubtypeSuffix) && WILDCARD_TYPE.equals(thisSubtypeNoSuffix)) {
@@ -575,6 +574,9 @@ public static MediaType parseMediaType(String mediaType) {
575574
}
576575
String type = fullType.substring(0, subIndex);
577576
String subtype = fullType.substring(subIndex + 1, fullType.length());
577+
if (WILDCARD_TYPE.equals(type) && !WILDCARD_TYPE.equals(subtype)) {
578+
throw new IllegalArgumentException("A wildcard type is legal only in '*/*' (all media types).");
579+
}
578580

579581
Map<String, String> parameters = null;
580582
if (parts.length > 1) {

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2010 the original author or authors.
2+
* Copyright 2002-2011 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,12 +23,13 @@
2323
import java.util.List;
2424
import java.util.Random;
2525

26-
import static org.junit.Assert.*;
2726
import org.junit.Test;
2827

2928
import org.springframework.core.convert.ConversionService;
3029
import org.springframework.core.convert.support.ConversionServiceFactory;
3130

31+
import static org.junit.Assert.*;
32+
3233
/**
3334
* @author Arjen Poutsma
3435
* @author Juergen Hoeller
@@ -127,6 +128,11 @@ public void parseMediaTypeNoSubtypeSlash() {
127128
MediaType.parseMediaType("audio/");
128129
}
129130

131+
@Test(expected = IllegalArgumentException.class)
132+
public void parseMediaTypeTypeRange() {
133+
MediaType.parseMediaType("*/json");
134+
}
135+
130136
@Test(expected = IllegalArgumentException.class)
131137
public void parseMediaTypeIllegalType() {
132138
MediaType.parseMediaType("audio(/basic");
@@ -496,4 +502,11 @@ public void testWithConversionService() {
496502
assertEquals(mediaType, conversionService.convert("application/xml", MediaType.class));
497503
}
498504

505+
@Test
506+
public void isConcrete() {
507+
assertTrue("text/plain not concrete", MediaType.TEXT_PLAIN.isConcrete());
508+
assertFalse("*/* concrete", MediaType.ALL.isConcrete());
509+
assertFalse("text/* concrete", new MediaType("text", "*").isConcrete());
510+
}
511+
499512
}

0 commit comments

Comments
 (0)