diff --git a/dotnet/src/webdriver/Cookie.cs b/dotnet/src/webdriver/Cookie.cs index 5d892fdc33706..2265d3a546638 100644 --- a/dotnet/src/webdriver/Cookie.cs +++ b/dotnet/src/webdriver/Cookie.cs @@ -36,54 +36,38 @@ public class Cookie private string cookieValue; private string cookiePath; private string cookieDomain; - private bool isHttpOnly; private string sameSite; + private bool isHttpOnly; private bool secure; private DateTime? cookieExpiry; private readonly string[] sameSiteValues = {"Strict", "Lax", "None"}; + /// + /// Initializes a new instance of the class with a specific name and value. + /// + /// The name of the cookie. + /// The value of the cookie. + /// If the name is or an empty string, + /// or if it contains a semi-colon. + /// If the value is . + public Cookie(string name, string value) + : this(name, value, null) + { + } + /// /// Initializes a new instance of the class with a specific name, - /// value, domain, path and expiration date. + /// value, and path. /// /// The name of the cookie. /// The value of the cookie. - /// The domain of the cookie. /// The path of the cookie. - /// The expiration date of the cookie. /// If the name is or an empty string, /// or if it contains a semi-colon. /// If the value is . - public Cookie(string name, string value, string domain, string path, DateTime? expiry) + public Cookie(string name, string value, string path) + : this(name, value, path, null) { - if (string.IsNullOrEmpty(name)) - { - throw new ArgumentException("Cookie name cannot be null or empty string", "name"); - } - - if (value == null) - { - throw new ArgumentNullException("value", "Cookie value cannot be null"); - } - - if (name.IndexOf(';') != -1) - { - throw new ArgumentException("Cookie names cannot contain a ';': " + name, "name"); - } - - this.cookieName = name; - this.cookieValue = value; - if (!string.IsNullOrEmpty(path)) - { - this.cookiePath = path; - } - - this.cookieDomain = StripPort(domain); - - if (expiry != null) - { - this.cookieExpiry = expiry; - } } /// @@ -102,6 +86,23 @@ public Cookie(string name, string value, string path, DateTime? expiry) { } + /// + /// Initializes a new instance of the class with a specific name, + /// value, domain, path and expiration date. + /// + /// The name of the cookie. + /// The value of the cookie. + /// The domain of the cookie. + /// The path of the cookie. + /// The expiration date of the cookie. + /// If the name is or an empty string, + /// or if it contains a semi-colon. + /// If the value is . + public Cookie(string name, string value, string domain, string path, DateTime? expiry) + : this(name, value, domain, path, expiry, false, false, null) + { + } + /// /// Initializes a new instance of the class with a specific name, /// value, domain, path and expiration date. @@ -119,8 +120,36 @@ public Cookie(string name, string value, string path, DateTime? expiry) /// If the value or currentUrl is . /// If the same site value is not valid or same site value is "None" but secure is set to false. public Cookie(string name, string value, string domain, string path, DateTime? expiry, bool secure, bool isHttpOnly, string sameSite) - : this(name, value, domain, path, expiry) - { + { + if (string.IsNullOrEmpty(name)) + { + throw new ArgumentException("Cookie name cannot be null or empty string", "name"); + } + + if (value == null) + { + throw new ArgumentNullException("value", "Cookie value cannot be null"); + } + + if (name.IndexOf(';') != -1) + { + throw new ArgumentException("Cookie names cannot contain a ';': " + name, "name"); + } + + this.cookieName = name; + this.cookieValue = value; + if (!string.IsNullOrEmpty(path)) + { + this.cookiePath = path; + } + + this.cookieDomain = StripPort(domain); + + if (expiry != null) + { + this.cookieExpiry = expiry; + } + this.isHttpOnly = isHttpOnly; this.secure = secure; @@ -131,42 +160,9 @@ public Cookie(string name, string value, string domain, string path, DateTime? e throw new ArgumentException("Invalid sameSite cookie value. It should either \"Lax\", \"Strict\" or \"None\" ", "sameSite"); } - if ("None".Equals(sameSite) && !this.secure) - { - throw new ArgumentException("Invalid cookie configuration: SameSite=None must be Secure"); - } - this.sameSite = sameSite; } } - - /// - /// Initializes a new instance of the class with a specific name, - /// value, and path. - /// - /// The name of the cookie. - /// The value of the cookie. - /// The path of the cookie. - /// If the name is or an empty string, - /// or if it contains a semi-colon. - /// If the value is . - public Cookie(string name, string value, string path) - : this(name, value, path, null) - { - } - - /// - /// Initializes a new instance of the class with a specific name and value. - /// - /// The name of the cookie. - /// The value of the cookie. - /// If the name is or an empty string, - /// or if it contains a semi-colon. - /// If the value is . - public Cookie(string name, string value) - : this(name, value, null, null) - { - } /// /// Gets the name of the cookie.