Skip to content

Commit

Permalink
* Fixed the bug in CookieEncoder if there are no cookie's set while
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nibin authored and trustin committed Jul 29, 2011
1 parent 0062cb7 commit 65fc361
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ private String encodeServerSide() {
}
}

sb.setLength(sb.length() - 1);
if(sb.length() > 0)
sb.setLength(sb.length() - 1);
return sb.toString();
}

Expand Down Expand Up @@ -205,7 +206,8 @@ private String encodeClientSide() {
}
}

sb.setLength(sb.length() - 1);
if(sb.length() > 0)
sb.setLength(sb.length() - 1);
return sb.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

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;
Expand Down Expand Up @@ -132,4 +133,16 @@ public void testEncodingMultipleCookies() {
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);

}

}

0 comments on commit 65fc361

Please sign in to comment.