Skip to content

Commit

Permalink
ContentTypes.extractMimePart will blow up if the passed contentType p…
Browse files Browse the repository at this point in the history
…arameter is null

SHINDIG-1975
Committed for Jiaging Guo


git-svn-id: https://svn.apache.org/repos/asf/shindig/trunk@1592741 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
ryanjbaxter committed May 6, 2014
1 parent 48205b6 commit 328bc12
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ private ContentTypes() {}
/**
* Extract the mime part from an Http Content-Type header
*/
public static String extractMimePart(String contentType) {
public static String extractMimePart(String contentType) throws InvalidContentTypeException {
if (Strings.isNullOrEmpty(contentType)) {
throw new InvalidContentTypeException("No Content-Type specified.");
}

contentType = contentType.trim();
int separator = contentType.indexOf(';');
if (separator != -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,14 @@ public void testStrictDisallowUnknown() throws Exception {
public void textExtractMimePart() throws Exception {
assertEquals("text/xml", ContentTypes.extractMimePart("Text/Xml ; charset = ISO-8859-1;x=y"));
}

@Test(expected=ContentTypes.InvalidContentTypeException.class)
public void testExtractMimePartNull() throws Exception {
ContentTypes.extractMimePart(null);
}

@Test(expected=ContentTypes.InvalidContentTypeException.class)
public void testExtractMimePartEmptyString() throws Exception {
ContentTypes.extractMimePart("");
}
}

0 comments on commit 328bc12

Please sign in to comment.