The parseMediaType method in the MediaType class of org.springframework.http appears to struggle with correctly detecting the MediaType for files whose names contain colons in their extensions.
Affected Version
Spring Boot version: 3.2.1 Problem Details When using the parseMediaType method to parse file media types, it fails to identify the MediaType correctly for files with names that include colons in the extension. Examples include:
app.qweqwe.js -> Does not detect MediaType app-qweqwe.js -> Detects MediaType correctly
Steps to Reproduce
Create a file named app.qweqwe.js. Use MediaType.parseMediaType to parse the file. Observe the failure to detect the MediaType.
Impact
This issue may impact applications relying on accurate MediaType detection for files, especially where file names contain colons in their extensions.
import org.springframework.http.MediaType;
String fileName = "app.qweqwe.js";
MediaType mediaType = MediaType.parseMediaType(fileName);
System.out.println("MediaType: " + mediaType);
Expected Outcome
The parseMediaType method should accurately identify the MediaType of files, regardless of colons in the file extension.
Actual Outcome
The parseMediaType method incorrectly identifies the MediaType of files with colons in their extensions.
Suggestion for Resolution
Reviewing and possibly revising the parsing algorithm in parseMediaType to handle file names with colons in the extension would be beneficial.
Comment From: quaff
MediaType::parseMediaType
accepts mediaType
not file name.