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:
Brian Clozel
2026-04-30 16:22:19 +02:00
committed by rstoyanchev
parent 3a91d90c28
commit 41cd6879bd
2 changed files with 11 additions and 2 deletions
@@ -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();