Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
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;
Expand Down Expand Up @@ -437,7 +437,9 @@ private void resolveBareType(String candidate) {

private void putParameter(String name, String value) {
if (this.parameters == null) {
this.parameters = new LinkedHashMap<>(4);
// Parameter names are case-insensitive, so use a case-insensitive
// map in order to reject duplicates that differ only in case.
this.parameters = new LinkedCaseInsensitiveMap<>(4, Locale.ROOT);
}
if (this.parameters.put(name, value) != null) {
throw new InvalidMimeTypeException(this.input, "duplicate parameter '" + name + "=" + value + "'");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ void valueOfDuplicateParameter() {
.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\"'");
}

}


Expand Down