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:
@@ -277,6 +277,13 @@ public class MimeTypeTests {
|
||||
assertEquals("Invalid amount of mime types", 0, mimeTypes.size());
|
||||
}
|
||||
|
||||
@Test // gh-23241
|
||||
public void parseMimeTypesWithTrailingComma() {
|
||||
List<MimeType> mimeTypes = MimeTypeUtils.parseMimeTypes("text/plain, text/html,");
|
||||
assertNotNull("No mime types returned", mimeTypes);
|
||||
assertEquals("Incorrect number of mime types", 2, mimeTypes.size());
|
||||
}
|
||||
|
||||
@Test // SPR-17459
|
||||
public void parseMimeTypesWithQuotedParameters() {
|
||||
testWithQuotedParameters("foo/bar;param=\",\"");
|
||||
|
||||
Reference in New Issue
Block a user