mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Fix parsing failure for MIME types with quoted pairs
Prior to this commit, MIME types with parameter values that contain a quoted pair would sometimes fail and parse an incomplete parameter value. This commit ensures that the quoted section of the parameter value is correctly handled. Fixes gh-36730
This commit is contained in:
committed by
rstoyanchev
parent
3a91d90c28
commit
41cd6879bd
@@ -238,7 +238,7 @@ public abstract class MimeTypeUtils {
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (ch == '"') {
|
||||
else if (ch == '"' && mimeType.charAt(nextIndex - 1) != '\\') {
|
||||
quoted = !quoted;
|
||||
}
|
||||
nextIndex++;
|
||||
|
||||
@@ -98,7 +98,7 @@ class MimeTypeTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void parseQuotedSeparator() {
|
||||
void parseQuotedParameterValue() {
|
||||
String s = "application/xop+xml;charset=utf-8;type=\"application/soap+xml;action=\\\"https://x.y.z\\\"\"";
|
||||
MimeType mimeType = MimeType.valueOf(s);
|
||||
assertThat(mimeType.getType()).as("Invalid type").isEqualTo("application");
|
||||
@@ -107,6 +107,15 @@ class MimeTypeTests {
|
||||
assertThat(mimeType.getParameter("type")).isEqualTo("\"application/soap+xml;action=\\\"https://x.y.z\\\"\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
void parseParameterWithQuotedPair() {
|
||||
String s = "text/plain;twelve=\"1\\\"2\"";
|
||||
MimeType mimeType = MimeType.valueOf(s);
|
||||
assertThat(mimeType.getType()).as("Invalid type").isEqualTo("text");
|
||||
assertThat(mimeType.getSubtype()).as("Invalid subtype").isEqualTo("plain");
|
||||
assertThat(mimeType.getParameter("twelve")).isEqualTo("\"1\\\"2\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
void withConversionService() {
|
||||
ConversionService conversionService = new DefaultConversionService();
|
||||
|
||||
Reference in New Issue
Block a user