Browse Source

backported fix for SPR-8697 from 3.1 RC2

3.0.x
Juergen Hoeller 14 years ago
parent
commit
6316a45927
  1. 4
      org.springframework.web/src/main/java/org/springframework/http/MediaType.java
  2. 17
      org.springframework.web/src/test/java/org/springframework/http/MediaTypeTests.java

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

@ -404,7 +404,6 @@ public class MediaType implements Comparable<MediaType> { @@ -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> { @@ -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) {

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

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* 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; @@ -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 { @@ -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 { @@ -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());
}
}

Loading…
Cancel
Save