* Fixed the bug in CookieEncoder if there are no cookie's set while
calling encode(). Without the fix, it ended up in calling the exception "java.lang.StringIndexOutOfBoundsException". * Also added test case to verify the patch Change-Id: Ib96425e07ab50be027ade7be0748cceb6438a586 Conflicts: src/test/java/org/jboss/netty/handler/codec/http/CookieEncoderTest.java
This commit is contained in:
parent
349b03b467
commit
bc8b92e1f7
@ -167,7 +167,10 @@ public class CookieEncoder {
|
||||
}
|
||||
}
|
||||
|
||||
sb.setLength(sb.length() - 1);
|
||||
if(sb.length() > 0) {
|
||||
sb.setLength(sb.length() - 1);
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@ -205,7 +208,8 @@ public class CookieEncoder {
|
||||
}
|
||||
}
|
||||
|
||||
sb.setLength(sb.length() - 1);
|
||||
if(sb.length() > 0)
|
||||
sb.setLength(sb.length() - 1);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,9 @@
|
||||
*/
|
||||
package org.jboss.netty.handler.codec.http;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.util.Date;
|
||||
@ -131,4 +133,16 @@ public class CookieEncoderTest {
|
||||
String encodedCookie = encoder.encode();
|
||||
assertEquals(c1 + c2 + c3, encodedCookie);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodingWithNoCookies() {
|
||||
CookieEncoder encoderForServer = new CookieEncoder(true);
|
||||
String encodedCookie1 = encoderForServer.encode();
|
||||
CookieEncoder encoderForClient = new CookieEncoder(false);
|
||||
String encodedCookie2 = encoderForClient.encode();
|
||||
assertNotNull(encodedCookie1);
|
||||
assertNotNull(encodedCookie2);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user