< prev index next >
src/share/classes/java/net/HttpCookie.java
Print this page
rev 1562 : 6901170: HttpCookie parsing of version and max-age mis-handled
Summary: Accept single quotes in cookies and better exception handling in CookieManager
Reviewed-by: chegar
@@ -990,11 +990,11 @@
public void assign(HttpCookie cookie, String attrName, String attrValue) {
try {
int version = Integer.parseInt(attrValue);
cookie.setVersion(version);
} catch (NumberFormatException ignored) {
- throw new IllegalArgumentException("Illegal cookie version attribute");
+ // Just ignore bogus version, it will default to 0 or 1
}
}
});
assignors.put("expires", new CookieAttributeAssignor(){ // Netscape only
public void assign(HttpCookie cookie, String attrName, String attrValue) {
@@ -1095,16 +1095,19 @@
return version;
}
private static String stripOffSurroundingQuote(String str) {
- if (str != null && str.length() > 0 &&
+ if (str != null && str.length() > 2 &&
str.charAt(0) == '"' && str.charAt(str.length() - 1) == '"') {
return str.substring(1, str.length() - 1);
- } else {
- return str;
}
+ if (str != null && str.length() > 2 &&
+ str.charAt(0) == '\'' && str.charAt(str.length() - 1) == '\'') {
+ return str.substring(1, str.length() - 1);
+ }
+ return str;
}
private static boolean equalsIgnoreCase(String s, String t) {
if (s == t) return true;
if ((s != null) && (t != null)) {
< prev index next >