Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Common/src/System/HexConverter.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable disable
using System.Diagnostics;
using System.Runtime.CompilerServices;

Expand Down Expand Up @@ -99,7 +98,7 @@ public static void EncodeToUtf16(ReadOnlySpan<byte> bytes, Span<char> chars, Cas
#endif
public static unsafe string ToString(ReadOnlySpan<byte> bytes, Casing casing = Casing.Upper)
{
#if NETFRAMEWORK || NETSTANDARD1_0 || NETSTANDARD1_3 || NETSTANDARD2_0
#if NETFRAMEWORK || NETSTANDARD1_0 || NETSTANDARD1_3 || NETSTANDARD2_0 || NETSTANDARD2_1
Span<char> result = stackalloc char[0];
if (bytes.Length > 16)
{
Expand Down
15 changes: 7 additions & 8 deletions Common/src/System/Net/CaseInsensitiveAscii.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable enable
using System.Collections;

namespace System.Net
Expand Down Expand Up @@ -42,7 +41,7 @@ internal class CaseInsensitiveAscii : IEqualityComparer, IComparer
// ASCII string case insensitive hash function
public int GetHashCode(object myObject)
{
string? myString = myObject as string;
string myString = myObject as string;
if (myString == null)
{
return 0;
Expand All @@ -57,10 +56,10 @@ public int GetHashCode(object myObject)
}

// ASCII string case insensitive comparer
public int Compare(object? firstObject, object? secondObject)
public int Compare(object firstObject, object secondObject)
{
string? firstString = firstObject as string;
string? secondString = secondObject as string;
string firstString = firstObject as string;
string secondString = secondObject as string;
if (firstString == null)
{
return secondString == null ? 0 : -1;
Expand Down Expand Up @@ -97,10 +96,10 @@ private int FastGetHashCode(string myString)
}

// ASCII string case insensitive comparer
public new bool Equals(object? firstObject, object? secondObject)
public new bool Equals(object firstObject, object secondObject)
{
string? firstString = firstObject as string;
string? secondString = secondObject as string;
string firstString = firstObject as string;
string secondString = secondObject as string;
if (firstString == null)
{
return secondString == null;
Expand Down
78 changes: 38 additions & 40 deletions Common/src/System/Net/CookieParser.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable enable
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.InteropServices;

namespace System.Net
{
Expand Down Expand Up @@ -45,7 +43,7 @@ internal struct CookieTokenizer
private bool _eofCookie;
private int _index;
private readonly int _length;
private string? _name;
private string _name;
private bool _quoted;
private int _start;
private CookieToken _token;
Expand Down Expand Up @@ -82,7 +80,7 @@ internal bool Eof
}
}

internal string? Name
internal string Name
{
get
{
Expand Down Expand Up @@ -450,7 +448,7 @@ internal CookieToken Token
}
}

internal bool IsEqualTo(string? value)
internal bool IsEqualTo(string value)
{
return string.Equals(_name, value, StringComparison.OrdinalIgnoreCase);
}
Expand Down Expand Up @@ -511,7 +509,7 @@ internal CookieToken TokenFromName(bool parseResponseCookies)
internal struct CookieParser
{
private CookieTokenizer _tokenizer;
private Cookie? _savedCookie;
private Cookie _savedCookie;

internal CookieParser(string cookieString)
{
Expand All @@ -525,8 +523,8 @@ private static bool InternalSetNameMethod(Cookie cookie, string? value)
return cookie.InternalSetName(value);
}
#else
private static Func<Cookie, string?, bool>? s_internalSetNameMethod;
private static Func<Cookie, string?, bool> InternalSetNameMethod
private static Func<Cookie, string, bool> s_internalSetNameMethod;
private static Func<Cookie, string, bool> InternalSetNameMethod
{
get
{
Expand All @@ -536,25 +534,25 @@ private static bool InternalSetNameMethod(Cookie cookie, string? value)
// We need to use Cookie.InternalSetName instead of the Cookie.set_Name wrapped in a try catch block, as
// Cookie.set_Name keeps the original name if the string is empty or null.
// Unfortunately this API is internal so we use reflection to access it. The method is cached for performance reasons.
MethodInfo? method = typeof(Cookie).GetMethod("InternalSetName", BindingFlags.Instance | BindingFlags.NonPublic);
MethodInfo method = typeof(Cookie).GetMethod("InternalSetName", BindingFlags.Instance | BindingFlags.NonPublic);
Debug.Assert(method != null, "We need to use an internal method named InternalSetName that is declared on Cookie.");
s_internalSetNameMethod = (Func<Cookie, string?, bool>)Delegate.CreateDelegate(typeof(Func<Cookie, string?, bool>), method);
s_internalSetNameMethod = (Func<Cookie, string, bool>)Delegate.CreateDelegate(typeof(Func<Cookie, string, bool>), method);
}

return s_internalSetNameMethod;
}
}
#endif

private static FieldInfo? s_isQuotedDomainField;
private static FieldInfo s_isQuotedDomainField;
private static FieldInfo IsQuotedDomainField
{
get
{
if (s_isQuotedDomainField == null)
{
// TODO https://github.com/dotnet/runtime/issues/19348:
FieldInfo? field = typeof(Cookie).GetField("IsQuotedDomain", BindingFlags.Instance | BindingFlags.NonPublic);
FieldInfo field = typeof(Cookie).GetField("IsQuotedDomain", BindingFlags.Instance | BindingFlags.NonPublic);
Debug.Assert(field != null, "We need to use an internal field named IsQuotedDomain that is declared on Cookie.");
s_isQuotedDomainField = field;
}
Expand All @@ -563,15 +561,15 @@ private static FieldInfo IsQuotedDomainField
}
}

private static FieldInfo? s_isQuotedVersionField;
private static FieldInfo s_isQuotedVersionField;
private static FieldInfo IsQuotedVersionField
{
get
{
if (s_isQuotedVersionField == null)
{
// TODO https://github.com/dotnet/runtime/issues/19348:
FieldInfo? field = typeof(Cookie).GetField("IsQuotedVersion", BindingFlags.Instance | BindingFlags.NonPublic);
FieldInfo field = typeof(Cookie).GetField("IsQuotedVersion", BindingFlags.Instance | BindingFlags.NonPublic);
Debug.Assert(field != null, "We need to use an internal field named IsQuotedVersion that is declared on Cookie.");
s_isQuotedVersionField = field;
}
Expand All @@ -583,9 +581,9 @@ private static FieldInfo IsQuotedVersionField
// Get
//
// Gets the next cookie or null if there are no more cookies.
internal Cookie? Get()
internal Cookie Get()
{
Cookie? cookie = null;
Cookie cookie = null;

// Only the first occurrence of an attribute value must be counted.
bool commentSet = false;
Expand Down Expand Up @@ -618,17 +616,17 @@ private static FieldInfo IsQuotedVersionField
if (!commentSet)
{
commentSet = true;
cookie!.Comment = _tokenizer.Value;
cookie.Comment = _tokenizer.Value;
}
break;

case CookieToken.CommentUrl:
if (!commentUriSet)
{
commentUriSet = true;
if (Uri.TryCreate(CheckQuoted(_tokenizer.Value), UriKind.Absolute, out Uri? parsed))
if (Uri.TryCreate(CheckQuoted(_tokenizer.Value), UriKind.Absolute, out Uri parsed))
{
cookie!.CommentUri = parsed;
cookie.CommentUri = parsed;
}
}
break;
Expand All @@ -637,7 +635,7 @@ private static FieldInfo IsQuotedVersionField
if (!domainSet)
{
domainSet = true;
cookie!.Domain = CheckQuoted(_tokenizer.Value);
cookie.Domain = CheckQuoted(_tokenizer.Value);
IsQuotedDomainField.SetValue(cookie, _tokenizer.Quoted);
}
break;
Expand All @@ -650,12 +648,12 @@ private static FieldInfo IsQuotedVersionField
if (DateTime.TryParse(CheckQuoted(_tokenizer.Value),
CultureInfo.InvariantCulture, DateTimeStyles.AllowWhiteSpaces | DateTimeStyles.AdjustToUniversal, out DateTime expires))
{
cookie!.Expires = expires;
cookie.Expires = expires;
}
else
{
// This cookie will be rejected
InternalSetNameMethod(cookie!, string.Empty);
InternalSetNameMethod(cookie, string.Empty);
}
}
break;
Expand All @@ -666,12 +664,12 @@ private static FieldInfo IsQuotedVersionField
expiresSet = true;
if (int.TryParse(CheckQuoted(_tokenizer.Value), out int parsed))
{
cookie!.Expires = DateTime.Now.AddSeconds(parsed);
cookie.Expires = DateTime.Now.AddSeconds(parsed);
}
else
{
// This cookie will be rejected
InternalSetNameMethod(cookie!, string.Empty);
InternalSetNameMethod(cookie, string.Empty);
}
}
break;
Expand All @@ -680,7 +678,7 @@ private static FieldInfo IsQuotedVersionField
if (!pathSet)
{
pathSet = true;
cookie!.Path = _tokenizer.Value;
cookie.Path = _tokenizer.Value;
}
break;

Expand All @@ -690,12 +688,12 @@ private static FieldInfo IsQuotedVersionField
portSet = true;
try
{
cookie!.Port = _tokenizer.Value;
cookie.Port = _tokenizer.Value;
}
catch
{
// This cookie will be rejected
InternalSetNameMethod(cookie!, string.Empty);
InternalSetNameMethod(cookie, string.Empty);
}
}
break;
Expand All @@ -707,13 +705,13 @@ private static FieldInfo IsQuotedVersionField
int parsed;
if (int.TryParse(CheckQuoted(_tokenizer.Value), out parsed))
{
cookie!.Version = parsed;
cookie.Version = parsed;
IsQuotedVersionField.SetValue(cookie, _tokenizer.Quoted);
}
else
{
// This cookie will be rejected
InternalSetNameMethod(cookie!, string.Empty);
InternalSetNameMethod(cookie, string.Empty);
}
}
break;
Expand All @@ -727,27 +725,27 @@ private static FieldInfo IsQuotedVersionField
if (!discardSet)
{
discardSet = true;
cookie!.Discard = true;
cookie.Discard = true;
}
break;

case CookieToken.Secure:
if (!secureSet)
{
secureSet = true;
cookie!.Secure = true;
cookie.Secure = true;
}
break;

case CookieToken.HttpOnly:
cookie!.HttpOnly = true;
cookie.HttpOnly = true;
break;

case CookieToken.Port:
if (!portSet)
{
portSet = true;
cookie!.Port = string.Empty;
cookie.Port = string.Empty;
}
break;
}
Expand All @@ -759,9 +757,9 @@ private static FieldInfo IsQuotedVersionField
return cookie;
}

internal Cookie? GetServer()
internal Cookie GetServer()
{
Cookie? cookie = _savedCookie;
Cookie cookie = _savedCookie;
_savedCookie = null;

// Only the first occurrence of an attribute value must be counted.
Expand Down Expand Up @@ -794,7 +792,7 @@ private static FieldInfo IsQuotedVersionField
if (!domainSet)
{
domainSet = true;
cookie!.Domain = CheckQuoted(_tokenizer.Value);
cookie.Domain = CheckQuoted(_tokenizer.Value);
IsQuotedDomainField.SetValue(cookie, _tokenizer.Quoted);
}
break;
Expand All @@ -803,7 +801,7 @@ private static FieldInfo IsQuotedVersionField
if (!pathSet)
{
pathSet = true;
cookie!.Path = _tokenizer.Value;
cookie.Path = _tokenizer.Value;
}
break;

Expand All @@ -813,12 +811,12 @@ private static FieldInfo IsQuotedVersionField
portSet = true;
try
{
cookie!.Port = _tokenizer.Value;
cookie.Port = _tokenizer.Value;
}
catch (CookieException)
{
// This cookie will be rejected
InternalSetNameMethod(cookie!, string.Empty);
InternalSetNameMethod(cookie, string.Empty);
}
}
break;
Expand All @@ -845,7 +843,7 @@ private static FieldInfo IsQuotedVersionField
if (_tokenizer.Token == CookieToken.Port && !portSet)
{
portSet = true;
cookie!.Port = string.Empty;
cookie.Port = string.Empty;
}
break;
}
Expand Down
Loading