Skip to content

Commit 6983988

Browse files
committed
Merge branch '7.0.x'
2 parents 2b7ec43 + 4d6e88d commit 6983988

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

‎spring-core/src/main/java/org/springframework/util/MimeTypeUtils.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public abstract class MimeTypeUtils {
187187

188188
/**
189189
* Parse the given String into a single {@code MimeType}.
190-
* Recently parsed {@code MimeType} are cached for further retrieval.
190+
* <p>Recently parsed {@code MimeType} values are cached for future retrieval.
191191
* @param mimeType the string to parse
192192
* @return the mime type
193193
* @throws InvalidMimeTypeException if the string cannot be parsed
@@ -238,7 +238,7 @@ private static MimeType parseMimeTypeInternal(String mimeType) {
238238
break;
239239
}
240240
}
241-
else if (ch == '"' && mimeType.charAt(nextIndex - 1) != '\\') {
241+
else if (ch == '"' && (nextIndex == 0 || mimeType.charAt(nextIndex - 1) != '\\')) {
242242
quoted = !quoted;
243243
}
244244
nextIndex++;

‎spring-core/src/test/java/org/springframework/util/MimeTypeTests.java‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ void parseQuotedParameterValue() {
108108
assertThat(mimeType.getParameter("type")).isEqualTo("\"application/soap+xml;action=\\\"https://x.y.z\\\"\"");
109109
}
110110

111-
@Test
111+
@Test // gh-36730
112112
void parseParameterWithQuotedPair() {
113113
String s = "text/plain;twelve=\"1\\\"2\"";
114114
MimeType mimeType = MimeType.valueOf(s);
@@ -303,6 +303,13 @@ void parseMimeTypeIllegalQuotedParameterValue() {
303303
MimeTypeUtils.parseMimeType("audio/*;attr=\""));
304304
}
305305

306+
@Test // gh-36971
307+
void parseMimeTypeWrappedInQuotes() {
308+
assertThatExceptionOfType(InvalidMimeTypeException.class)
309+
.isThrownBy(() -> MimeTypeUtils.parseMimeType("\"application/xml\""))
310+
.withMessageContaining("Invalid token character '\"'");
311+
}
312+
306313
@Test
307314
void parseMimeTypeNull() {
308315
assertThatExceptionOfType(InvalidMimeTypeException.class).isThrownBy(() ->

0 commit comments

Comments
 (0)