Skip to content
Permalink
Browse files

Merge pull request #54 from vladimirralev/issue53

Issue53
  • Loading branch information
vladimirralev committed Jan 6, 2020
2 parents b1a5142 + a15978d commit 9c6dea9e51b991192529bc0176c62c9cf22a7d38
@@ -498,17 +498,24 @@ protected String encodeBody() {

protected StringBuilder encodeBody(StringBuilder buffer) {
ListIterator<HDR> iterator = this.listIterator();

while (true) {
SIPHeader sipHeader = (SIPHeader) iterator.next();
if ( sipHeader == this ) throw new RuntimeException ("Unexpected circularity in SipHeaderList");

//This determines if a null body was added https://github.com/usnistgov/jsip/issues/53
int buffPosDelta = buffer.length();
sipHeader.encodeBody(buffer);
buffPosDelta -= buffer.length(); // if 0 nothing was added to the buffer
// if (body.equals("")) System.out.println("BODY == ");
if (iterator.hasNext()) {
if (!this.headerName.equals(PrivacyHeader.NAME))
buffer.append(Separators.COMMA);
else
buffer.append(Separators.SEMICOLON);
continue;
if(buffPosDelta != 0) {
if (!this.headerName.equals(PrivacyHeader.NAME))
buffer.append(Separators.COMMA);
else
buffer.append(Separators.SEMICOLON);
continue;
}
} else
break;

@@ -24,6 +24,8 @@
*/
package test.unit.gov.nist.javax.sip.parser;

import gov.nist.javax.sip.header.Supported;
import gov.nist.javax.sip.header.SupportedList;
import gov.nist.javax.sip.parser.SupportedParser;

/**
@@ -45,5 +47,19 @@ public void testParser() {
super.testParser(SupportedParser.class,content);

}

/*
* Test for https://github.com/usnistgov/jsip/issues/53
* Adding two Supported headers, first one "" causes malformed encoding output:
*
* "Support: ,timer"
*/
public void testMalformedConstruction() {
SupportedList supportedList = new SupportedList();
supportedList.add(new Supported(""));
supportedList.add(new Supported("timer"));
String encoded = supportedList.encode();
assertEquals("Supported: timer\r\n", encoded);
}

}

0 comments on commit 9c6dea9

Please sign in to comment.
You can’t perform that action at this time.