Skip to content

Commit

Permalink
fix a fringe case when parsing a multipart body with empty lines and no
Browse files Browse the repository at this point in the history
leading empty line.
  • Loading branch information
jagliot committed Jun 8, 2017
1 parent 87f76ca commit 160fb6a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/gov/nist/javax/sip/message/MultipartMimeContentImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,15 @@ private ContentImpl parseBodyPart(String bodyPart) throws ParseException {
// the body and don't split on any crlf in the body
String[] nextPartSplit = bodyPart.split("\r?\n\r?\n", 2);

bodyContent = bodyPart;

if (nextPartSplit.length == 2) {
headers = nextPartSplit[0].split("\r?\n");
bodyContent = nextPartSplit[1];
} else {
bodyContent = bodyPart;
// since we aren't completely sure the data is a header let's test the first one
String potentialHeaders[] = nextPartSplit[0].split("\r?\n");
if (potentialHeaders[0].indexOf(":") > 0) {
headers = potentialHeaders;
bodyContent = nextPartSplit[1];
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ public class MultipartMimeParserTest extends TestCase {
+ "a=fmtp:101 0-15\n"
+ "\n";

private static String isup = "^A^P`^@\n"
+"^C^F^M^C���^G^C^P^Tf49^U\n"
+"\n"
+ "�^S^U^@at�D^Q^E�^A^@�^G^C^P^T6pw\"�^C^Px'�&^@^@\"\n"
+ "\n";

private static String multipartContentWithEmptyLine = "\n"
+ "--boundary1\n"
+ "Content-Type: message/sip\n"
Expand Down Expand Up @@ -402,6 +408,22 @@ public void testMultiPartMimeMarshallingAndUnMarshallingWithANonMultiPartBodyWit
MultipartMimeContent multipartMimeContent2 = request.getMultipartMimeContent();
checkSimpleBody(multipartMimeContent2);
}

public void testMultiPartMimeMarshallingAndUnMarshallingWithANonMultiPartBodyWithAnEmptyLineWithNoLeadingLine() throws Exception {
SIPRequest request = new SIPRequest();
byte[] content = isup.getBytes("UTF-8");
ContentType contentType = new ContentType("application", "sdp");
request.setContent(content, contentType);
MultipartMimeContent multipartMimeContent = request.getMultipartMimeContent();
checkSimpleBody(multipartMimeContent);

// let's now marshall back the body and reparse it to check consistency
// we just want the content, not the boundaries (which are null)
String bodyContent = multipartMimeContent.getContents().next().getContent().toString();
request.setContent(bodyContent, contentType);
MultipartMimeContent multipartMimeContent2 = request.getMultipartMimeContent();
checkSimpleBody(multipartMimeContent2);
}

private void checkMultiPart(MultipartMimeContent multipartMimeContent) {
Iterator<Content> partContentIterator = multipartMimeContent.getContents();
Expand Down

0 comments on commit 160fb6a

Please sign in to comment.