2323using System . Linq ;
2424using System . Text . Json . Serialization ;
2525
26+ #nullable enable
27+
2628namespace OpenQA . Selenium
2729{
2830 /// <summary>
@@ -33,9 +35,9 @@ public class Cookie
3335 {
3436 private string cookieName ;
3537 private string cookieValue ;
36- private string cookiePath ;
37- private string cookieDomain ;
38- private string sameSite ;
38+ private string ? cookiePath ;
39+ private string ? cookieDomain ;
40+ private string ? sameSite ;
3941 private bool isHttpOnly ;
4042 private bool secure ;
4143 private DateTime ? cookieExpiry ;
@@ -64,7 +66,7 @@ public Cookie(string name, string value)
6466 /// <exception cref="ArgumentException">If the name is <see langword="null"/> or an empty string,
6567 /// or if it contains a semi-colon.</exception>
6668 /// <exception cref="ArgumentNullException">If the value is <see langword="null"/>.</exception>
67- public Cookie ( string name , string value , string path )
69+ public Cookie ( string name , string value , string ? path )
6870 : this ( name , value , path , null )
6971 {
7072 }
@@ -80,7 +82,7 @@ public Cookie(string name, string value, string path)
8082 /// <exception cref="ArgumentException">If the name is <see langword="null"/> or an empty string,
8183 /// or if it contains a semi-colon.</exception>
8284 /// <exception cref="ArgumentNullException">If the value is <see langword="null"/>.</exception>
83- public Cookie ( string name , string value , string path , DateTime ? expiry )
85+ public Cookie ( string name , string value , string ? path , DateTime ? expiry )
8486 : this ( name , value , null , path , expiry )
8587 {
8688 }
@@ -97,7 +99,7 @@ public Cookie(string name, string value, string path, DateTime? expiry)
9799 /// <exception cref="ArgumentException">If the name is <see langword="null"/> or an empty string,
98100 /// or if it contains a semi-colon.</exception>
99101 /// <exception cref="ArgumentNullException">If the value is <see langword="null"/>.</exception>
100- public Cookie ( string name , string value , string domain , string path , DateTime ? expiry )
102+ public Cookie ( string name , string value , string ? domain , string ? path , DateTime ? expiry )
101103 : this ( name , value , domain , path , expiry , false , false , null )
102104 {
103105 }
@@ -117,7 +119,7 @@ public Cookie(string name, string value, string domain, string path, DateTime? e
117119 /// <exception cref="ArgumentException">If the name and value are both an empty string,
118120 /// if the name contains a semi-colon, or if same site value is not valid.</exception>
119121 /// <exception cref="ArgumentNullException">If the name, value or currentUrl is <see langword="null"/>.</exception>
120- public Cookie ( string name , string value , string domain , string path , DateTime ? expiry , bool secure , bool isHttpOnly , string sameSite )
122+ public Cookie ( string name , string value , string ? domain , string ? path , DateTime ? expiry , bool secure , bool isHttpOnly , string ? sameSite )
121123 {
122124 if ( name == null )
123125 {
@@ -190,7 +192,7 @@ public string Value
190192 /// </summary>
191193 [ JsonPropertyName ( "domain" ) ]
192194 [ JsonIgnore ( Condition = JsonIgnoreCondition . WhenWritingNull ) ]
193- public string Domain
195+ public string ? Domain
194196 {
195197 get { return this . cookieDomain ; }
196198 }
@@ -200,7 +202,7 @@ public string Domain
200202 /// </summary>
201203 [ JsonPropertyName ( "path" ) ]
202204 [ JsonIgnore ( Condition = JsonIgnoreCondition . WhenWritingNull ) ]
203- public virtual string Path
205+ public virtual string ? Path
204206 {
205207 get { return this . cookiePath ; }
206208 }
@@ -229,7 +231,7 @@ public virtual bool IsHttpOnly
229231 /// </summary>
230232 [ JsonPropertyName ( "sameSite" ) ]
231233 [ JsonIgnore ( Condition = JsonIgnoreCondition . WhenWritingNull ) ]
232- public virtual string SameSite
234+ public virtual string ? SameSite
233235 {
234236 get { return this . sameSite ; }
235237 }
@@ -272,27 +274,28 @@ internal long? ExpirySeconds
272274 /// </summary>
273275 /// <param name="rawCookie">The Dictionary object containing the cookie parameters.</param>
274276 /// <returns>A <see cref="Cookie"/> object with the proper parameters set.</returns>
277+ /// <exception cref="ArgumentNullException">If <paramref name="rawCookie"/> is null.</exception>
275278 public static Cookie FromDictionary ( Dictionary < string , object > rawCookie )
276279 {
277280 if ( rawCookie == null )
278281 {
279282 throw new ArgumentNullException ( nameof ( rawCookie ) , "Dictionary cannot be null" ) ;
280283 }
281284
282- string name = rawCookie [ "name" ] . ToString ( ) ;
285+ string name = rawCookie [ "name" ] . ToString ( ) ! ;
283286 string value = string . Empty ;
284287 if ( rawCookie [ "value" ] != null )
285288 {
286- value = rawCookie [ "value" ] . ToString ( ) ;
289+ value = rawCookie [ "value" ] . ToString ( ) ! ;
287290 }
288291
289- string path = "/" ;
292+ string ? path = "/" ;
290293 if ( rawCookie . ContainsKey ( "path" ) && rawCookie [ "path" ] != null )
291294 {
292295 path = rawCookie [ "path" ] . ToString ( ) ;
293296 }
294297
295- string domain = string . Empty ;
298+ string ? domain = string . Empty ;
296299 if ( rawCookie . ContainsKey ( "domain" ) && rawCookie [ "domain" ] != null )
297300 {
298301 domain = rawCookie [ "domain" ] . ToString ( ) ;
@@ -307,16 +310,16 @@ public static Cookie FromDictionary(Dictionary<string, object> rawCookie)
307310 bool secure = false ;
308311 if ( rawCookie . ContainsKey ( "secure" ) && rawCookie [ "secure" ] != null )
309312 {
310- secure = bool . Parse ( rawCookie [ "secure" ] . ToString ( ) ) ;
313+ secure = bool . Parse ( rawCookie [ "secure" ] . ToString ( ) ! ) ;
311314 }
312315
313316 bool isHttpOnly = false ;
314317 if ( rawCookie . ContainsKey ( "httpOnly" ) && rawCookie [ "httpOnly" ] != null )
315318 {
316- isHttpOnly = bool . Parse ( rawCookie [ "httpOnly" ] . ToString ( ) ) ;
319+ isHttpOnly = bool . Parse ( rawCookie [ "httpOnly" ] . ToString ( ) ! ) ;
317320 }
318321
319- string sameSite = null ;
322+ string ? sameSite = null ;
320323 if ( rawCookie . ContainsKey ( "sameSite" ) && rawCookie [ "sameSite" ] != null )
321324 {
322325 sameSite = rawCookie [ "sameSite" ] . ToString ( ) ;
@@ -347,10 +350,10 @@ public override string ToString()
347350 /// <returns><see langword="true"/> if the specified <see cref="object">Object</see>
348351 /// is equal to the current <see cref="object">Object</see>; otherwise,
349352 /// <see langword="false"/>.</returns>
350- public override bool Equals ( object obj )
353+ public override bool Equals ( object ? obj )
351354 {
352355 // Two cookies are equal if the name and value match
353- Cookie cookie = obj as Cookie ;
356+ Cookie ? cookie = obj as Cookie ;
354357
355358 if ( this == obj )
356359 {
@@ -367,7 +370,7 @@ public override bool Equals(object obj)
367370 return false ;
368371 }
369372
370- return ! ( this . cookieValue != null ? ! this . cookieValue . Equals ( cookie . cookieValue ) : cookie . Value != null ) ;
373+ return string . Equals ( this . cookieValue , cookie . cookieValue ) ;
371374 }
372375
373376 /// <summary>
@@ -379,12 +382,12 @@ public override int GetHashCode()
379382 return this . cookieName . GetHashCode ( ) ;
380383 }
381384
382- private static string StripPort ( string domain )
385+ private static string ? StripPort ( string ? domain )
383386 {
384- return string . IsNullOrEmpty ( domain ) ? null : domain . Split ( ':' ) [ 0 ] ;
387+ return string . IsNullOrEmpty ( domain ) ? null : domain ! . Split ( ':' ) [ 0 ] ;
385388 }
386389
387- private static DateTime ? ConvertExpirationTime ( string expirationTime )
390+ private static DateTime ? ConvertExpirationTime ( string ? expirationTime )
388391 {
389392 DateTime ? expires = null ;
390393 double seconds = 0 ;
0 commit comments