From a248a525756923e20e159b56fee7eddb8a709a29 Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Tue, 19 Oct 2021 11:53:22 +0200 Subject: [PATCH] Revert transitive MediaType comparators The fix made for gh-27488 resulted in a change of the default order of codecs. This commit reverts these changes, so that the previous order is restored. Closes gh-27573 --- .../src/main/java/org/springframework/util/MimeType.java | 6 ++++++ .../src/main/java/org/springframework/http/MediaType.java | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/spring-core/src/main/java/org/springframework/util/MimeType.java b/spring-core/src/main/java/org/springframework/util/MimeType.java index b6e1ff2ff3..de29040b07 100644 --- a/spring-core/src/main/java/org/springframework/util/MimeType.java +++ b/spring-core/src/main/java/org/springframework/util/MimeType.java @@ -637,6 +637,9 @@ public class MimeType implements Comparable, Serializable { else if (mimeType2.isWildcardType() && !mimeType1.isWildcardType()) { // audio/* > */* return -1; } + else if (!mimeType1.getType().equals(mimeType2.getType())) { // audio/basic == text/html + return 0; + } else { // mediaType1.getType().equals(mediaType2.getType()) if (mimeType1.isWildcardSubtype() && !mimeType2.isWildcardSubtype()) { // audio/* < audio/basic return 1; @@ -644,6 +647,9 @@ public class MimeType implements Comparable, Serializable { else if (mimeType2.isWildcardSubtype() && !mimeType1.isWildcardSubtype()) { // audio/basic > audio/* return -1; } + else if (!mimeType1.getSubtype().equals(mimeType2.getSubtype())) { // audio/basic == audio/wave + return 0; + } else { // mediaType2.getSubtype().equals(mediaType2.getSubtype()) return compareParameters(mimeType1, mimeType2); } diff --git a/spring-web/src/main/java/org/springframework/http/MediaType.java b/spring-web/src/main/java/org/springframework/http/MediaType.java index 34d05d41d3..729555add9 100644 --- a/spring-web/src/main/java/org/springframework/http/MediaType.java +++ b/spring-web/src/main/java/org/springframework/http/MediaType.java @@ -798,6 +798,9 @@ public class MediaType extends MimeType implements Serializable { else if (mediaType2.isWildcardType() && !mediaType1.isWildcardType()) { // audio/* > */* return -1; } + else if (!mediaType1.getType().equals(mediaType2.getType())) { // audio/basic == text/html + return 0; + } else { // mediaType1.getType().equals(mediaType2.getType()) if (mediaType1.isWildcardSubtype() && !mediaType2.isWildcardSubtype()) { // audio/* < audio/basic return 1; @@ -805,6 +808,9 @@ public class MediaType extends MimeType implements Serializable { else if (mediaType2.isWildcardSubtype() && !mediaType1.isWildcardSubtype()) { // audio/basic > audio/* return -1; } + else if (!mediaType1.getSubtype().equals(mediaType2.getSubtype())) { // audio/basic == audio/wave + return 0; + } else { int paramsSize1 = mediaType1.getParameters().size(); int paramsSize2 = mediaType2.getParameters().size();