File tree Expand file tree Collapse file tree
main/java/org/springframework/util
test/java/org/springframework/util Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ++;
Original file line number Diff line number Diff 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 (() ->
You can’t perform that action at this time.
0 commit comments