From b034fd7253236f7d98759713dc9bfc5cb42ac9fe Mon Sep 17 00:00:00 2001 From: Luke Inman-Semerau Date: Mon, 1 Feb 2016 12:24:36 -0800 Subject: [PATCH] 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 --- .../remote/server/handler/AddCookie.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/java/server/src/org/openqa/selenium/remote/server/handler/AddCookie.java b/java/server/src/org/openqa/selenium/remote/server/handler/AddCookie.java index 3d619f4e094aa..83e57826c375d 100644 --- a/java/server/src/org/openqa/selenium/remote/server/handler/AddCookie.java +++ b/java/server/src/org/openqa/selenium/remote/server/handler/AddCookie.java @@ -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( @@ -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() + "]";