Skip to content

Commit 39479f3

Browse files
committed
Polish MimeTypeUtil.
Author: Tomoya Honjo <[email protected]>
1 parent 775bccc commit 39479f3

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@ public static MimeType parseMimeType(String mimeType) {
219219
if (!StringUtils.hasLength(mimeType)) {
220220
throw new InvalidMimeTypeException(mimeType, "'mimeType' must not be empty");
221221
}
222+
if (mimeType.startsWith(";")) {
223+
throw new InvalidMimeTypeException(mimeType, "does not contain any type");
224+
}
225+
222226
String[] parts = StringUtils.tokenizeToStringArray(mimeType, ";");
223227

224228
String fullType = parts[0].trim();

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ public void parseMimeType() throws Exception {
164164
assertEquals("Invalid subtype", "*", mimeType.getSubtype());
165165
}
166166

167+
@Test(expected = InvalidMimeTypeException.class)
168+
public void parseMimeTypeNoType() {
169+
MimeTypeUtils.parseMimeType(";");
170+
}
171+
167172
@Test(expected = InvalidMimeTypeException.class)
168173
public void parseMimeTypeNoSubtype() {
169174
MimeTypeUtils.parseMimeType("audio");

0 commit comments

Comments
 (0)