mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-21 21:39:05 +00:00
Handle MIME type parameter names case-insensitively
MIME type parameter names are case-insensitive, and MimeType already stores them in a LinkedCaseInsensitiveMap. Several code paths, however, still compared them with case-sensitive String.equals(). As a result, MimeType.hashCode() disagreed with MimeType.equals() for parameter names that differ only in case, breaking the equals/hashCode contract: text/plain;FOO=bar and text/plain;foo=bar are equal but hash differently, so one is not found in a hash-based collection holding the other. MimeType.compareTo() had the same blind spot for the charset parameter. MediaType was affected in two further ways: an out-of-range quality value escaped validation when spelled Q=, and removeQualityValue() left a Q= parameter in place. Signed-off-by: Artyom Tsvirko <36863599+lArtiquel@users.noreply.github.com>
This commit is contained in:
committed by
Brian Clozel
parent
ee19b96ee9
commit
2028eb3694
@@ -135,6 +135,12 @@ class MediaTypeTests {
|
||||
MediaType.parseMediaType("audio/basic;q=1.1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void parseMediaTypeIllegalQualityFactorWithUpperCaseParameterName() {
|
||||
assertThatExceptionOfType(InvalidMediaTypeException.class).isThrownBy(() ->
|
||||
MediaType.parseMediaType("audio/basic;Q=1.1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void parseMediaTypeIllegalCharset() {
|
||||
assertThatExceptionOfType(InvalidMediaTypeException.class).isThrownBy(() ->
|
||||
@@ -293,6 +299,18 @@ class MediaTypeTests {
|
||||
assertThat(new MediaType("text", "*").isConcrete()).as("text/* concrete").isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void removeQualityValue() {
|
||||
assertThat(MediaType.parseMediaType("audio/basic;q=0.8").removeQualityValue())
|
||||
.isEqualTo(MediaType.parseMediaType("audio/basic"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void removeQualityValueWithUpperCaseParameterName() {
|
||||
assertThat(MediaType.parseMediaType("audio/basic;Q=0.8").removeQualityValue())
|
||||
.isEqualTo(MediaType.parseMediaType("audio/basic"));
|
||||
}
|
||||
|
||||
@Test // gh-26127
|
||||
void serialize() throws Exception {
|
||||
MediaType original = new MediaType("text", "plain", StandardCharsets.UTF_8);
|
||||
|
||||
Reference in New Issue
Block a user