Skip to content

Commit c8fdee5

Browse files
committed
[dotnet] according to the rfc section 5.3 a cookie name is allowed to be an empty string so long as the value is not also an empty string
1 parent fe6c189 commit c8fdee5

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

dotnet/src/webdriver/Cookie.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,22 +115,27 @@ public Cookie(string name, string value, string domain, string path, DateTime? e
115115
/// <param name="isSecure"><see langword="true"/> if the cookie is secure; otherwise <see langword="false"/></param>
116116
/// <param name="isHttpOnly"><see langword="true"/> if the cookie is an HTTP-only cookie; otherwise <see langword="false"/></param>
117117
/// <param name="sameSite">The SameSite value of cookie.</param>
118-
/// <exception cref="ArgumentException">If the name is <see langword="null"/> or an empty string,
119-
/// or if it contains a semi-colon.</exception>
120-
/// <exception cref="ArgumentNullException">If the value or currentUrl is <see langword="null"/>.</exception>
118+
/// <exception cref="ArgumentException">If the name and value are both an empty string,
119+
/// or if the name contains a semi-colon.</exception>
120+
/// <exception cref="ArgumentNullException">If the name, value or currentUrl is <see langword="null"/>.</exception>
121121
/// <exception cref="ArgumentNullException">If the same site value is not valid or same site value is "None" but secure is set to false.</exception>
122122
public Cookie(string name, string value, string domain, string path, DateTime? expiry, bool secure, bool isHttpOnly, string sameSite)
123123
{
124-
if (string.IsNullOrEmpty(name))
124+
if (name == null)
125125
{
126-
throw new ArgumentException("Cookie name cannot be null or empty string", nameof(name));
126+
throw new ArgumentNullException(nameof(value), "Cookie name cannot be null");
127127
}
128128

129129
if (value == null)
130130
{
131131
throw new ArgumentNullException(nameof(value), "Cookie value cannot be null");
132132
}
133133

134+
if (name == string.Empty && value == string.Empty)
135+
{
136+
throw new ArgumentException("Cookie name and value cannot both be empty string");
137+
}
138+
134139
if (name.IndexOf(';') != -1)
135140
{
136141
throw new ArgumentException("Cookie names cannot contain a ';': " + name, nameof(name));

dotnet/test/common/CookieTest.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ public void ShouldThrowAnExceptionWhenSemiColonExistsInTheCookieAttribute()
1919
Assert.That(() => new ReturnedCookie("hi;hi", "value", null, null, DateTime.Now, false, false), Throws.InstanceOf<ArgumentException>());
2020
}
2121

22+
[Test]
23+
public void ShouldThrowAnExceptionWhenNameAndValueAreEmpty()
24+
{
25+
Assert.That(() => new ReturnedCookie("", "", null, null, DateTime.Now, false, false), Throws.InstanceOf<ArgumentException>());
26+
}
27+
2228
[Test]
2329
public void ShouldThrowAnExceptionWhenTheNameIsNull()
2430
{

0 commit comments

Comments
 (0)