Skip to content

Commit b034fd7

Browse files
committed
be a bit fault tolerant with boolean cookie attributes and check if the string value is true, also allow the serialization of httponly... unknown if it can actually be set on the client side though
Fixes #1575
1 parent ee4eb06 commit b034fd7

File tree

1 file changed

+16
-4
lines changed
  • java/server/src/org/openqa/selenium/remote/server/handler

1 file changed

+16
-4
lines changed

java/server/src/org/openqa/selenium/remote/server/handler/AddCookie.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,8 @@ protected Cookie createCookie() {
6262
String value = (String) rawCookie.get("value");
6363
String path = (String) rawCookie.get("path");
6464
String domain = (String) rawCookie.get("domain");
65-
Boolean secure = (Boolean) rawCookie.get("secure");
66-
if (secure == null) {
67-
secure = false;
68-
}
65+
boolean secure = getBooleanFromRaw("secure");
66+
boolean httpOnly = getBooleanFromRaw("httpOnly");
6967

7068
Number expiryNum = (Number) rawCookie.get("expiry");
7169
Date expiry = expiryNum == null ? null : new Date(
@@ -76,9 +74,23 @@ protected Cookie createCookie() {
7674
.domain(domain)
7775
.isSecure(secure)
7876
.expiresOn(expiry)
77+
.isHttpOnly(httpOnly)
7978
.build();
8079
}
8180

81+
private boolean getBooleanFromRaw(String key) {
82+
if (rawCookie.containsKey(key)) {
83+
Object value = rawCookie.get(key);
84+
if (value instanceof Boolean) {
85+
return (Boolean) value;
86+
}
87+
if (value instanceof String) {
88+
return ((String) value).equalsIgnoreCase("true");
89+
}
90+
}
91+
return false;
92+
}
93+
8294
@Override
8395
public String toString() {
8496
return "[add cookie: " + createCookie() + "]";

0 commit comments

Comments
 (0)