Skip to content

Commit

Permalink
be a bit fault tolerant with boolean cookie attributes and check if t…
Browse files Browse the repository at this point in the history
…he string value is true, also allow the serialization of httponly... unknown if it can actually be set on the client side though

Fixes SeleniumHQ#1575
  • Loading branch information
lukeis committed Feb 1, 2016
1 parent ee4eb06 commit b034fd7
Showing 1 changed file with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,8 @@ protected Cookie createCookie() {
String value = (String) rawCookie.get("value");
String path = (String) rawCookie.get("path");
String domain = (String) rawCookie.get("domain");
Boolean secure = (Boolean) rawCookie.get("secure");
if (secure == null) {
secure = false;
}
boolean secure = getBooleanFromRaw("secure");
boolean httpOnly = getBooleanFromRaw("httpOnly");

Number expiryNum = (Number) rawCookie.get("expiry");
Date expiry = expiryNum == null ? null : new Date(
Expand All @@ -76,9 +74,23 @@ protected Cookie createCookie() {
.domain(domain)
.isSecure(secure)
.expiresOn(expiry)
.isHttpOnly(httpOnly)
.build();
}

private boolean getBooleanFromRaw(String key) {
if (rawCookie.containsKey(key)) {
Object value = rawCookie.get(key);
if (value instanceof Boolean) {
return (Boolean) value;
}
if (value instanceof String) {
return ((String) value).equalsIgnoreCase("true");
}
}
return false;
}

@Override
public String toString() {
return "[add cookie: " + createCookie() + "]";
Expand Down

0 comments on commit b034fd7

Please sign in to comment.