提交 6316a459 编写于 作者: J Juergen Hoeller

backported fix for SPR-8697 from 3.1 RC2

上级 e298c202
......@@ -404,7 +404,6 @@ public class MediaType implements Comparable<MediaType> {
int otherPlusIdx = other.subtype.indexOf('+');
if (thisPlusIdx != -1 && otherPlusIdx != -1) {
String thisSubtypeNoSuffix = this.subtype.substring(0, thisPlusIdx);
String thisSubtypeSuffix = this.subtype.substring(thisPlusIdx + 1);
String otherSubtypeSuffix = other.subtype.substring(otherPlusIdx + 1);
if (thisSubtypeSuffix.equals(otherSubtypeSuffix) && WILDCARD_TYPE.equals(thisSubtypeNoSuffix)) {
......@@ -575,6 +574,9 @@ public class MediaType implements Comparable<MediaType> {
}
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<String, String> parameters = null;
if (parts.length > 1) {
......
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -23,12 +23,13 @@ import java.util.Comparator;
import java.util.List;
import java.util.Random;
import static org.junit.Assert.*;
import org.junit.Test;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.support.ConversionServiceFactory;
import static org.junit.Assert.*;
/**
* @author Arjen Poutsma
* @author Juergen Hoeller
......@@ -127,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");
......@@ -496,4 +502,11 @@ public class MediaTypeTests {
assertEquals(mediaType, conversionService.convert("application/xml", MediaType.class));
}
@Test
public void isConcrete() {
assertTrue("text/plain not concrete", MediaType.TEXT_PLAIN.isConcrete());
assertFalse("*/* concrete", MediaType.ALL.isConcrete());
assertFalse("text/* concrete", new MediaType("text", "*").isConcrete());
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册