Ignore empty entries when parsing MediaTypes and MimeTypes
Prior to Spring Framework 5.1.3, MimeTypeUtils.parseMimeTypes() and MediaType.parseMediaTypes() ignored empty entries, but 5.1.3 introduced a regression in that an empty entry -- for example, due to a trailing comma in the list of media types in an HTTP Accept header -- would result in a "406 Not Acceptable" response status. This commit fixes this by filtering out empty entries before parsing them into MimeType and MediaType instances. Empty entries are therefore effectively ignored. Fixes gh-23241
This commit is contained in:
@@ -38,6 +38,7 @@ import org.springframework.lang.Nullable;
|
||||
* @author Arjen Poutsma
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Dimitrios Liapis
|
||||
* @author Sam Brannen
|
||||
* @since 4.0
|
||||
*/
|
||||
public abstract class MimeTypeUtils {
|
||||
@@ -259,10 +260,11 @@ public abstract class MimeTypeUtils {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return tokenize(mimeTypes).stream()
|
||||
.map(MimeTypeUtils::parseMimeType).collect(Collectors.toList());
|
||||
.filter(StringUtils::hasText)
|
||||
.map(MimeTypeUtils::parseMimeType)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tokenize the given comma-separated string of {@code MimeType} objects
|
||||
* into a {@code List<String>}. Unlike simple tokenization by ",", this
|
||||
|
||||
Reference in New Issue
Block a user