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 77d7661254b..c92d71815cc 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 @@ -324,11 +324,15 @@ public class MediaType implements Comparable { if (comp != 0) { return comp; } - Iterator thisAttributes = new TreeSet(this.parameters.keySet()).iterator(); - Iterator otherAttributes = new TreeSet(other.parameters.keySet()).iterator(); - while (thisAttributes.hasNext()) { - String thisAttribute = thisAttributes.next(); - String otherAttribute = otherAttributes.next(); + TreeSet thisAttributes = new TreeSet(String.CASE_INSENSITIVE_ORDER); + thisAttributes.addAll(this.parameters.keySet()); + TreeSet otherAttributes = new TreeSet(String.CASE_INSENSITIVE_ORDER); + otherAttributes.addAll(other.parameters.keySet()); + Iterator thisAttributesIterator = thisAttributes.iterator(); + Iterator otherAttributesIterator = otherAttributes.iterator(); + while (thisAttributesIterator.hasNext()) { + String thisAttribute = thisAttributesIterator.next(); + String otherAttribute = otherAttributesIterator.next(); comp = thisAttribute.compareToIgnoreCase(otherAttribute); if (comp != 0) { return comp; @@ -355,7 +359,7 @@ public class MediaType implements Comparable { return false; } MediaType otherType = (MediaType) other; - return (this.type.equals(otherType.type) && this.subtype.equals(otherType.subtype) && + return (this.type.equalsIgnoreCase(otherType.type) && this.subtype.equalsIgnoreCase(otherType.subtype) && this.parameters.equals(otherType.parameters)); } 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 7a18d90baca..c5f6db33a80 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 @@ -214,6 +214,12 @@ public class MediaTypeTests { assertEquals("Media types not equal", m1, m2); assertEquals("compareTo() not consistent with equals", 0, m1.compareTo(m2)); assertEquals("compareTo() not consistent with equals", 0, m2.compareTo(m1)); + + m1 = MediaType.parseMediaType("text/html; q=0.7; charset=iso-8859-1"); + m2 = MediaType.parseMediaType("text/html; Q=0.7; charset=iso-8859-1"); + assertEquals("Media types not equal", m1, m2); + assertEquals("compareTo() not consistent with equals", 0, m1.compareTo(m2)); + assertEquals("compareTo() not consistent with equals", 0, m2.compareTo(m1)); } @Test @@ -232,6 +238,8 @@ public class MediaTypeTests { m2 = new MediaType("audio", "basic", Collections.singletonMap("foo", "Bar")); assertTrue("Invalid comparison result", m1.compareTo(m2) != 0); assertTrue("Invalid comparison result", m2.compareTo(m1) != 0); + + } @Test