* 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
This commit is contained in:
parent
0062cb743c
commit
65fc361eec
@ -167,7 +167,8 @@ public class CookieEncoder {
|
||||
}
|
||||
}
|
||||
|
||||
sb.setLength(sb.length() - 1);
|
||||
if(sb.length() > 0)
|
||||
sb.setLength(sb.length() - 1);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@ -205,7 +206,8 @@ public class CookieEncoder {
|
||||
}
|
||||
}
|
||||
|
||||
sb.setLength(sb.length() - 1);
|
||||
if(sb.length() > 0)
|
||||
sb.setLength(sb.length() - 1);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,7 @@ package org.jboss.netty.handler.codec.http;
|
||||
|
||||
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;
|
||||
@ -132,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