mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-17 08:24:13 +00:00
Reject MIME type parameters differing only in case
MIME type parameter names are case-insensitive, but MimeTypeParser accumulates parameters in a case-sensitive LinkedHashMap. As a result, duplicate parameters differing only in case (such as "charset" and "CHARSET") were not rejected and were silently collapsed to the last value by the case-insensitive parameter map of MimeType. Accumulate parameters in a LinkedCaseInsensitiveMap so that duplicates differing only in case map to the same key and are rejected consistently with exact duplicates. Signed-off-by: junhyeong9812 <pickjog@gmail.com> Co-authored-by: Yash <190389954+yashsiwacha@users.noreply.github.com>
This commit is contained in:
committed by
Brian Clozel
co-authored by
Yash
parent
dd110d4604
commit
bc66622342
@@ -23,8 +23,8 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.function.BiPredicate;
|
||||
@@ -437,7 +437,7 @@ public abstract class MimeTypeUtils {
|
||||
|
||||
private void putParameter(String name, String value) {
|
||||
if (this.parameters == null) {
|
||||
this.parameters = new LinkedHashMap<>(4);
|
||||
this.parameters = new LinkedCaseInsensitiveMap<>(4, Locale.ROOT);
|
||||
}
|
||||
if (this.parameters.put(name, value) != null) {
|
||||
throw new InvalidMimeTypeException(this.input, "duplicate parameter '" + name + "=" + value + "'");
|
||||
|
||||
@@ -174,6 +174,12 @@ class MimeTypeTests {
|
||||
.hasMessageContaining("Invalid mime type \"text/plain;dupe=\"1\";dupe=\"2\"\": duplicate parameter 'dupe=\"2\"'");
|
||||
}
|
||||
|
||||
@Test
|
||||
void valueOfDuplicateParameterWithDifferentCase() {
|
||||
assertThatThrownBy(() -> MimeType.valueOf("text/plain;dupe=\"1\";DUPE=\"2\"")).isInstanceOf(InvalidMimeTypeException.class)
|
||||
.hasMessageContaining("Invalid mime type \"text/plain;dupe=\"1\";DUPE=\"2\"\": duplicate parameter 'DUPE=\"2\"'");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user