Imported Upstream version 6.12.0.86

Former-commit-id: 7a84ce7d08c42c458ac8e74b27186ca863315d79
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2020-07-10 08:44:59 +00:00
parent 92747312ea
commit 0b380204a4
812 changed files with 26901 additions and 9053 deletions

View File

@@ -0,0 +1 @@
4c73d086958f94da084c33cd2530c0a2a819e361

View File

@@ -78,10 +78,6 @@ namespace System.Globalization
[OptionalField(VersionAdded = 3)]
private SortVersion m_SortVersion; // Do not rename (binary serialization)
// _invariantMode is defined for the perf reason as accessing the instance field is faster than access the static property GlobalizationMode.Invariant
[NonSerialized]
private readonly bool _invariantMode = GlobalizationMode.Invariant;
private int culture; // Do not rename (binary serialization). The fields sole purpose is to support Desktop serialization.
internal CompareInfo(CultureInfo culture)
@@ -340,7 +336,7 @@ namespace System.Globalization
return (1); // non-null > null
}
if (_invariantMode)
if (GlobalizationMode.Invariant)
{
if ((options & CompareOptions.IgnoreCase) != 0)
return CompareOrdinalIgnoreCase(string1, string2);
@@ -387,7 +383,7 @@ namespace System.Globalization
return 1;
}
if (_invariantMode)
if (GlobalizationMode.Invariant)
{
return (options & CompareOptions.IgnoreCase) != 0 ?
CompareOrdinalIgnoreCase(string1, string2.AsSpan()) :
@@ -403,7 +399,7 @@ namespace System.Globalization
if (string1.Length == 0 || string2.Length == 0)
return string1.Length - string2.Length;
return _invariantMode ?
return GlobalizationMode.Invariant ?
string.CompareOrdinal(string1, string2) :
CompareString(string1, string2, CompareOptions.None);
}
@@ -414,7 +410,7 @@ namespace System.Globalization
if (string1.Length == 0 || string2.Length == 0)
return string1.Length - string2.Length;
return _invariantMode ?
return GlobalizationMode.Invariant ?
CompareOrdinalIgnoreCase(string1, string2) :
CompareString(string1, string2, CompareOptions.IgnoreCase);
}
@@ -515,7 +511,7 @@ namespace System.Globalization
return string.CompareOrdinal(span1, span2);
}
if (_invariantMode)
if (GlobalizationMode.Invariant)
{
if ((options & CompareOptions.IgnoreCase) != 0)
return CompareOrdinalIgnoreCase(span1, span2);
@@ -633,7 +629,7 @@ namespace System.Globalization
throw new ArgumentException(SR.Argument_InvalidFlag, nameof(options));
}
if (_invariantMode)
if (GlobalizationMode.Invariant)
{
return source.StartsWith(prefix, (options & CompareOptions.IgnoreCase) != 0 ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal);
}
@@ -646,7 +642,7 @@ namespace System.Globalization
Debug.Assert(prefix.Length != 0);
Debug.Assert(source.Length != 0);
Debug.Assert((options & ValidIndexMaskOffFlags) == 0);
Debug.Assert(!_invariantMode);
Debug.Assert(!GlobalizationMode.Invariant);
Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
return StartsWith(source, prefix, options);
@@ -698,7 +694,7 @@ namespace System.Globalization
throw new ArgumentException(SR.Argument_InvalidFlag, nameof(options));
}
if (_invariantMode)
if (GlobalizationMode.Invariant)
{
return source.EndsWith(suffix, (options & CompareOptions.IgnoreCase) != 0 ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal);
}
@@ -711,7 +707,7 @@ namespace System.Globalization
Debug.Assert(suffix.Length != 0);
Debug.Assert(source.Length != 0);
Debug.Assert((options & ValidIndexMaskOffFlags) == 0);
Debug.Assert(!_invariantMode);
Debug.Assert(!GlobalizationMode.Invariant);
Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
return EndsWith(source, suffix, options);
@@ -844,7 +840,7 @@ namespace System.Globalization
if ((options & ValidIndexMaskOffFlags) != 0 && (options != CompareOptions.Ordinal))
throw new ArgumentException(SR.Argument_InvalidFlag, nameof(options));
if (_invariantMode)
if (GlobalizationMode.Invariant)
return IndexOfOrdinal(source, new string(value, 1), startIndex, count, ignoreCase: (options & (CompareOptions.IgnoreCase | CompareOptions.OrdinalIgnoreCase)) != 0);
return IndexOfCore(source, new string(value, 1), startIndex, count, options, null);
@@ -892,7 +888,7 @@ namespace System.Globalization
if ((options & ValidIndexMaskOffFlags) != 0 && (options != CompareOptions.Ordinal))
throw new ArgumentException(SR.Argument_InvalidFlag, nameof(options));
if (_invariantMode)
if (GlobalizationMode.Invariant)
return IndexOfOrdinal(source, value, startIndex, count, ignoreCase: (options & (CompareOptions.IgnoreCase | CompareOptions.OrdinalIgnoreCase)) != 0);
return IndexOfCore(source, value, startIndex, count, options, null);
@@ -900,7 +896,7 @@ namespace System.Globalization
internal int IndexOfOrdinal(ReadOnlySpan<char> source, ReadOnlySpan<char> value, bool ignoreCase)
{
Debug.Assert(!_invariantMode);
Debug.Assert(!GlobalizationMode.Invariant);
Debug.Assert(!source.IsEmpty);
Debug.Assert(!value.IsEmpty);
return IndexOfOrdinalCore(source, value, ignoreCase);
@@ -908,7 +904,7 @@ namespace System.Globalization
internal unsafe int IndexOf(ReadOnlySpan<char> source, ReadOnlySpan<char> value, CompareOptions options)
{
Debug.Assert(!_invariantMode);
Debug.Assert(!GlobalizationMode.Invariant);
Debug.Assert(!source.IsEmpty);
Debug.Assert(!value.IsEmpty);
return IndexOfCore(source, value, options, null);
@@ -948,7 +944,7 @@ namespace System.Globalization
return res;
}
if (_invariantMode)
if (GlobalizationMode.Invariant)
{
int res = IndexOfOrdinal(source, value, startIndex, count, ignoreCase: (options & (CompareOptions.IgnoreCase | CompareOptions.OrdinalIgnoreCase)) != 0);
if (res >= 0)
@@ -963,7 +959,7 @@ namespace System.Globalization
internal int IndexOfOrdinal(string source, string value, int startIndex, int count, bool ignoreCase)
{
if (_invariantMode)
if (GlobalizationMode.Invariant)
{
return InvariantIndexOf(source, value, startIndex, count, ignoreCase);
}
@@ -1098,7 +1094,7 @@ namespace System.Globalization
return source.LastIndexOf(value.ToString(), startIndex, count, StringComparison.OrdinalIgnoreCase);
}
if (_invariantMode)
if (GlobalizationMode.Invariant)
return InvariantLastIndexOf(source, new string(value, 1), startIndex, count, (options & (CompareOptions.IgnoreCase | CompareOptions.OrdinalIgnoreCase)) != 0);
return LastIndexOfCore(source, value.ToString(), startIndex, count, options);
@@ -1149,7 +1145,7 @@ namespace System.Globalization
return LastIndexOfOrdinal(source, value, startIndex, count, ignoreCase: true);
}
if (_invariantMode)
if (GlobalizationMode.Invariant)
return InvariantLastIndexOf(source, value, startIndex, count, (options & (CompareOptions.IgnoreCase | CompareOptions.OrdinalIgnoreCase)) != 0);
return LastIndexOfCore(source, value, startIndex, count, options);
@@ -1157,7 +1153,7 @@ namespace System.Globalization
internal int LastIndexOfOrdinal(string source, string value, int startIndex, int count, bool ignoreCase)
{
if (_invariantMode)
if (GlobalizationMode.Invariant)
{
return InvariantLastIndexOf(source, value, startIndex, count, ignoreCase);
}
@@ -1174,7 +1170,7 @@ namespace System.Globalization
////////////////////////////////////////////////////////////////////////
public virtual SortKey GetSortKey(string source, CompareOptions options)
{
if (_invariantMode)
if (GlobalizationMode.Invariant)
return InvariantCreateSortKey(source, options);
return CreateSortKey(source, options);
@@ -1183,7 +1179,7 @@ namespace System.Globalization
public virtual SortKey GetSortKey(string source)
{
if (_invariantMode)
if (GlobalizationMode.Invariant)
return InvariantCreateSortKey(source, CompareOptions.None);
return CreateSortKey(source, CompareOptions.None);
@@ -1297,7 +1293,7 @@ namespace System.Globalization
throw new ArgumentException(SR.Argument_InvalidFlag, nameof(options));
}
if (_invariantMode)
if (GlobalizationMode.Invariant)
{
return ((options & CompareOptions.IgnoreCase) != 0) ? GetIgnoreCaseHash(source) : source.GetHashCode();
}
@@ -1349,7 +1345,7 @@ namespace System.Globalization
{
if (m_SortVersion == null)
{
if (_invariantMode)
if (GlobalizationMode.Invariant)
{
m_SortVersion = new SortVersion(0, CultureInfo.LOCALE_INVARIANT, new Guid(0, 0, 0, 0, 0, 0, 0,
(byte) (CultureInfo.LOCALE_INVARIANT >> 24),

View File

@@ -297,17 +297,17 @@ namespace System.Globalization
return (((ch) == 0x20) || ((ch) >= 0x09 && (ch) <= 0x0D));
}
private static unsafe char* MatchChars(char* p, string str)
private static unsafe char* MatchChars(char* p, char* pEnd, string str)
{
fixed (char* stringPointer = str)
{
return MatchChars(p, stringPointer);
return MatchChars(p, pEnd, stringPointer);
}
}
private static unsafe char* MatchChars(char* p, char* str)
private static unsafe char* MatchChars(char* p, char* pEnd, char* str)
{
Debug.Assert(p != null && str != null);
Debug.Assert(p != null && pEnd != null && p <= pEnd && str != null);
if (*str == '\0')
{
@@ -317,8 +317,13 @@ namespace System.Globalization
// We only hurt the failure case
// This fix is for French or Kazakh cultures. Since a user cannot type 0xA0 as a
// space character we use 0x20 space character instead to mean the same.
while (*p == *str || (*str == '\u00a0' && *p == '\u0020'))
while (true)
{
char cp = p < pEnd ? *p : '\0';
if (cp != *str && !(*str == '\u00a0' && cp == '\u0020'))
{
break;
}
p++;
str++;
if (*str == '\0') return p;
@@ -326,8 +331,12 @@ namespace System.Globalization
return null;
}
private static unsafe bool ParseNumber(ref char* str, NumberStyles options, ref NumberBuffer number, StringBuilder sb, NumberFormatInfo numfmt, bool parseDecimal)
private static unsafe bool ParseNumber(ref char* str, char* strEnd, NumberStyles options, ref NumberBuffer number, StringBuilder sb, NumberFormatInfo numfmt, bool parseDecimal)
{
Debug.Assert(str != null);
Debug.Assert(strEnd != null);
Debug.Assert(str <= strEnd);
const int StateSign = 0x0001;
const int StateParens = 0x0002;
const int StateDigits = 0x0004;
@@ -362,7 +371,7 @@ namespace System.Globalization
int maxParseDigits = bigNumber ? int.MaxValue : NumberMaxDigits;
char* p = str;
char ch = *p;
char ch = p < strEnd ? *p : '\0';
char* next;
char* dig = number.digits;
@@ -373,7 +382,7 @@ namespace System.Globalization
// "-Kr 1231.47" is legal but "- 1231.47" is not.
if (!IsWhite(ch) || (options & NumberStyles.AllowLeadingWhite) == 0 || ((state & StateSign) != 0 && ((state & StateCurrency) == 0 && numfmt.NumberNegativePattern != 2)))
{
if ((((options & NumberStyles.AllowLeadingSign) != 0) && (state & StateSign) == 0) && ((next = MatchChars(p, numfmt.PositiveSign)) != null || ((next = MatchChars(p, numfmt.NegativeSign)) != null && (number.sign = true))))
if ((((options & NumberStyles.AllowLeadingSign) != 0) && (state & StateSign) == 0) && ((next = MatchChars(p, strEnd, numfmt.PositiveSign)) != null || ((next = MatchChars(p, strEnd, numfmt.NegativeSign)) != null && (number.sign = true))))
{
state |= StateSign;
p = next - 1;
@@ -383,7 +392,7 @@ namespace System.Globalization
state |= StateSign | StateParens;
number.sign = true;
}
else if (currSymbol != null && (next = MatchChars(p, currSymbol)) != null)
else if (currSymbol != null && (next = MatchChars(p, strEnd, currSymbol)) != null)
{
state |= StateCurrency;
currSymbol = null;
@@ -397,7 +406,7 @@ namespace System.Globalization
break;
}
}
ch = *++p;
ch = ++p < strEnd ? *p : '\0';
}
int digCount = 0;
@@ -437,12 +446,12 @@ namespace System.Globalization
number.scale--;
}
}
else if (((options & NumberStyles.AllowDecimalPoint) != 0) && ((state & StateDecimal) == 0) && ((next = MatchChars(p, decSep)) != null || ((parsingCurrency) && (state & StateCurrency) == 0) && (next = MatchChars(p, numfmt.NumberDecimalSeparator)) != null))
else if (((options & NumberStyles.AllowDecimalPoint) != 0) && ((state & StateDecimal) == 0) && ((next = MatchChars(p, strEnd, decSep)) != null || ((parsingCurrency) && (state & StateCurrency) == 0) && (next = MatchChars(p, strEnd, numfmt.NumberDecimalSeparator)) != null))
{
state |= StateDecimal;
p = next - 1;
}
else if (((options & NumberStyles.AllowThousands) != 0) && ((state & StateDigits) != 0) && ((state & StateDecimal) == 0) && ((next = MatchChars(p, groupSep)) != null || ((parsingCurrency) && (state & StateCurrency) == 0) && (next = MatchChars(p, numfmt.NumberGroupSeparator)) != null))
else if (((options & NumberStyles.AllowThousands) != 0) && ((state & StateDigits) != 0) && ((state & StateDecimal) == 0) && ((next = MatchChars(p, strEnd, groupSep)) != null || ((parsingCurrency) && (state & StateCurrency) == 0) && (next = MatchChars(p, strEnd, numfmt.NumberGroupSeparator)) != null))
{
p = next - 1;
}
@@ -450,7 +459,7 @@ namespace System.Globalization
{
break;
}
ch = *++p;
ch = ++p < strEnd ? *p : '\0';
}
bool negExp = false;
@@ -464,14 +473,14 @@ namespace System.Globalization
if ((ch == 'E' || ch == 'e') && ((options & NumberStyles.AllowExponent) != 0))
{
char* temp = p;
ch = *++p;
if ((next = MatchChars(p, numfmt.PositiveSign)) != null)
ch = ++p < strEnd ? *p : '\0';
if ((next = MatchChars(p, strEnd, numfmt.PositiveSign)) != null)
{
ch = *(p = next);
ch = (p = next) < strEnd ? *p : '\0';
}
else if ((next = MatchChars(p, numfmt.NegativeSign)) != null)
else if ((next = MatchChars(p, strEnd, numfmt.NegativeSign)) != null)
{
ch = *(p = next);
ch = (p = next) < strEnd ? *p : '\0';
negExp = true;
}
if (ch >= '0' && ch <= '9')
@@ -480,13 +489,13 @@ namespace System.Globalization
do
{
exp = exp * 10 + (ch - '0');
ch = *++p;
ch = ++p < strEnd ? *p : '\0';
if (exp > 1000)
{
exp = 9999;
while (ch >= '0' && ch <= '9')
{
ch = *++p;
ch = ++p < strEnd ? *p : '\0';
}
}
} while (ch >= '0' && ch <= '9');
@@ -499,14 +508,14 @@ namespace System.Globalization
else
{
p = temp;
ch = *p;
ch = p < strEnd ? *p : '\0';
}
}
while (true)
{
if (!IsWhite(ch) || (options & NumberStyles.AllowTrailingWhite) == 0)
{
if (((options & NumberStyles.AllowTrailingSign) != 0 && ((state & StateSign) == 0)) && ((next = MatchChars(p, numfmt.PositiveSign)) != null || (((next = MatchChars(p, numfmt.NegativeSign)) != null) && (number.sign = true))))
if (((options & NumberStyles.AllowTrailingSign) != 0 && ((state & StateSign) == 0)) && ((next = MatchChars(p, strEnd, numfmt.PositiveSign)) != null || (((next = MatchChars(p, strEnd, numfmt.NegativeSign)) != null) && (number.sign = true))))
{
state |= StateSign;
p = next - 1;
@@ -515,7 +524,7 @@ namespace System.Globalization
{
state &= ~StateParens;
}
else if (currSymbol != null && (next = MatchChars(p, currSymbol)) != null)
else if (currSymbol != null && (next = MatchChars(p, strEnd, currSymbol)) != null)
{
currSymbol = null;
p = next - 1;
@@ -525,7 +534,7 @@ namespace System.Globalization
break;
}
}
ch = *++p;
ch = ++p < strEnd ? *p : '\0';
}
if ((state & StateParens) == 0)
{
@@ -568,7 +577,7 @@ namespace System.Globalization
fixed (char* stringPointer = &MemoryMarshal.GetReference(str))
{
char* p = stringPointer;
if (!ParseNumber(ref p, options, ref number, sb, numfmt, parseDecimal)
if (!ParseNumber(ref p, p + str.Length, options, ref number, sb, numfmt, parseDecimal)
|| (p - stringPointer < str.Length && !TrailingZeros(str, (int)(p - stringPointer))))
{
return false;

View File

@@ -234,6 +234,7 @@ namespace System.Collections.Tests
}
[Fact]
[SkipOnTargetFramework(TargetFrameworkMonikers.Mono, "Flaky test - OOM")]
public void Ctor_Int_Int_GenerateNewPrime()
{
// The ctor for Hashtable performs the following calculation:

View File

@@ -5,7 +5,6 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Text;
namespace System.Net.Http.Headers
@@ -425,7 +424,7 @@ namespace System.Net.Http.Headers
}
// Returns input for decoding failures, as the content might not be encoded.
private string EncodeAndQuoteMime(string input)
private static string EncodeAndQuoteMime(string input)
{
string result = input;
bool needsQuotes = false;
@@ -441,7 +440,7 @@ namespace System.Net.Http.Headers
throw new ArgumentException(string.Format(CultureInfo.InvariantCulture,
SR.net_http_headers_invalid_value, input));
}
else if (RequiresEncoding(result))
else if (HeaderUtilities.ContainsNonAscii(result))
{
needsQuotes = true; // Encoded data must always be quoted, the equals signs are invalid in tokens.
result = EncodeMime(result); // =?utf-8?B?asdfasdfaesdf?=
@@ -460,7 +459,7 @@ namespace System.Net.Http.Headers
}
// Returns true if the value starts and ends with a quote.
private bool IsQuoted(string value)
private static bool IsQuoted(string value)
{
Debug.Assert(value != null);
@@ -468,23 +467,8 @@ namespace System.Net.Http.Headers
&& value.EndsWith("\"", StringComparison.Ordinal);
}
// tspecials are required to be in a quoted string. Only non-ascii needs to be encoded.
private bool RequiresEncoding(string input)
{
Debug.Assert(input != null);
foreach (char c in input)
{
if ((int)c > 0x7f)
{
return true;
}
}
return false;
}
// Encode using MIME encoding.
private string EncodeMime(string input)
private static string EncodeMime(string input)
{
byte[] buffer = Encoding.UTF8.GetBytes(input);
string encodedName = Convert.ToBase64String(buffer);
@@ -492,7 +476,7 @@ namespace System.Net.Http.Headers
}
// Attempt to decode MIME encoded strings.
private bool TryDecodeMime(string input, out string output)
private static bool TryDecodeMime(string input, out string output)
{
Debug.Assert(input != null);
@@ -535,7 +519,7 @@ namespace System.Net.Http.Headers
// Attempt to decode using RFC 5987 encoding.
// encoding'language'my%20string
private bool TryDecode5987(string input, out string output)
private static bool TryDecode5987(string input, out string output)
{
output = null;

View File

@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Buffers;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.Contracts;
@@ -66,58 +67,63 @@ namespace System.Net.Http.Headers
}
}
internal static bool ContainsNonAscii(string input)
{
Debug.Assert(input != null);
foreach (char c in input)
{
if ((int)c > 0x7f)
{
return true;
}
}
return false;
}
// Encode a string using RFC 5987 encoding.
// encoding'lang'PercentEncodedSpecials
internal static string Encode5987(string input)
{
string output;
IsInputEncoded5987(input, out output);
return output;
}
internal static bool IsInputEncoded5987(string input, out string output)
{
// Encode a string using RFC 5987 encoding.
// encoding'lang'PercentEncodedSpecials
bool wasEncoded = false;
StringBuilder builder = StringBuilderCache.Acquire();
byte[] utf8bytes = ArrayPool<byte>.Shared.Rent(Encoding.UTF8.GetMaxByteCount(input.Length));
int utf8length = Encoding.UTF8.GetBytes(input, 0, input.Length, utf8bytes, 0);
builder.Append("utf-8\'\'");
foreach (char c in input)
for (int i = 0; i < utf8length; i++)
{
byte utf8byte = utf8bytes[i];
// attr-char = ALPHA / DIGIT / "!" / "#" / "$" / "&" / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~"
// ; token except ( "*" / "'" / "%" )
if (c > 0x7F) // Encodes as multiple utf-8 bytes
if (utf8byte > 0x7F) // Encodes as multiple utf-8 bytes
{
byte[] bytes = Encoding.UTF8.GetBytes(c.ToString());
foreach (byte b in bytes)
{
AddHexEscaped((char)b, builder);
wasEncoded = true;
}
AddHexEscaped(utf8byte, builder);
}
else if (!HttpRuleParser.IsTokenChar(c) || c == '*' || c == '\'' || c == '%')
else if (!HttpRuleParser.IsTokenChar((char)utf8byte) || utf8byte == '*' || utf8byte == '\'' || utf8byte == '%')
{
// ASCII - Only one encoded byte.
AddHexEscaped(c, builder);
wasEncoded = true;
AddHexEscaped(utf8byte, builder);
}
else
{
builder.Append(c);
builder.Append((char)utf8byte);
}
}
output = StringBuilderCache.GetStringAndRelease(builder);
return wasEncoded;
Array.Clear(utf8bytes, 0, utf8length);
ArrayPool<byte>.Shared.Return(utf8bytes);
return StringBuilderCache.GetStringAndRelease(builder);
}
/// <summary>Transforms an ASCII character into its hexadecimal representation, adding the characters to a StringBuilder.</summary>
private static void AddHexEscaped(char c, StringBuilder destination)
private static void AddHexEscaped(byte c, StringBuilder destination)
{
Debug.Assert(destination != null);
Debug.Assert(c <= 0xFF);
destination.Append('%');
destination.Append(s_hexUpperChars[(c & 0xf0) >> 4]);

View File

@@ -337,10 +337,21 @@ namespace System.Net.Http
return CopyToAsyncCore(new ValueTask(task));
}
}
#if MONOTOUCH_WATCH
catch (Exception e)
{
if (StreamCopyExceptionNeedsWrapping(e))
{
return Task.FromException(GetStreamCopyException(e));
}
throw;
}
#else
catch (Exception e) when (StreamCopyExceptionNeedsWrapping(e))
{
return Task.FromException(GetStreamCopyException(e));
}
#endif
}
private static async Task CopyToAsyncCore(ValueTask copyTask)
@@ -349,10 +360,21 @@ namespace System.Net.Http
{
await copyTask.ConfigureAwait(false);
}
#if MONOTOUCH_WATCH
catch (Exception e)
{
if (StreamCopyExceptionNeedsWrapping(e))
{
throw GetStreamCopyException(e);
}
throw;
}
#else
catch (Exception e) when (StreamCopyExceptionNeedsWrapping(e))
{
throw GetStreamCopyException(e);
}
#endif
}
public Task CopyToAsync(Stream stream)
@@ -403,10 +425,21 @@ namespace System.Net.Http
CheckTaskNotNull(task);
return LoadIntoBufferAsyncCore(task, tempBuffer);
}
#if MONOTOUCH_WATCH
catch (Exception e)
{
if (StreamCopyExceptionNeedsWrapping(e))
{
return Task.FromException(GetStreamCopyException(e));
}
throw;
}
#else
catch (Exception e) when (StreamCopyExceptionNeedsWrapping(e))
{
return Task.FromException(GetStreamCopyException(e));
}
#endif
// other synchronous exceptions from SerializeToStreamAsync/CheckTaskNotNull will propagate
}

View File

@@ -91,9 +91,9 @@ namespace System.Net.Http
}
else
{
string usernameStar;
if (HeaderUtilities.IsInputEncoded5987(credential.UserName, out usernameStar))
if (HeaderUtilities.ContainsNonAscii(credential.UserName))
{
string usernameStar = HeaderUtilities.Encode5987(credential.UserName);
sb.AppendKeyValue(UsernameStar, usernameStar, includeQuotes: false);
}
else
@@ -408,6 +408,9 @@ namespace System.Net.Http
internal static class StringBuilderExtensions
{
// Characters that require escaping in quoted string
private static readonly char[] SpecialCharacters = new[] { '"', '\\' };
public static void AppendKeyValue(this StringBuilder sb, string key, string value, bool includeQuotes = true, bool includeComma = true)
{
sb.Append(key);
@@ -415,13 +418,30 @@ namespace System.Net.Http
if (includeQuotes)
{
sb.Append('"');
}
sb.Append(value);
if (includeQuotes)
{
int lastSpecialIndex = 0;
int specialIndex;
while (true)
{
specialIndex = value.IndexOfAny(SpecialCharacters, lastSpecialIndex);
if (specialIndex >= 0)
{
sb.Append(value, lastSpecialIndex, specialIndex - lastSpecialIndex);
sb.Append('\\');
sb.Append(value[specialIndex]);
lastSpecialIndex = specialIndex + 1;
}
else
{
sb.Append(value, lastSpecialIndex, value.Length - lastSpecialIndex);
break;
}
}
sb.Append('"');
}
else
{
sb.Append(value);
}
if (includeComma)
{

View File

@@ -115,10 +115,21 @@ namespace System.Net.Http
}
}
}
#if MONOTOUCH_WATCH
catch (Exception exc)
{
if (CancellationHelper.ShouldWrapInOperationCanceledException(exc, cancellationToken))
{
throw CancellationHelper.CreateOperationCanceledException(exc, cancellationToken);
}
throw;
}
#else
catch (Exception exc) when (CancellationHelper.ShouldWrapInOperationCanceledException(exc, cancellationToken))
{
throw CancellationHelper.CreateOperationCanceledException(exc, cancellationToken);
}
#endif
finally
{
ctr.Dispose();
@@ -161,10 +172,21 @@ namespace System.Net.Http
await _connection.FillAsync().ConfigureAwait(false);
}
}
#if MONOTOUCH_WATCH
catch (Exception exc)
{
if (CancellationHelper.ShouldWrapInOperationCanceledException(exc, cancellationToken))
{
throw CancellationHelper.CreateOperationCanceledException(exc, cancellationToken);
}
throw;
}
#else
catch (Exception exc) when (CancellationHelper.ShouldWrapInOperationCanceledException(exc, cancellationToken))
{
throw CancellationHelper.CreateOperationCanceledException(exc, cancellationToken);
}
#endif
finally
{
ctr.Dispose();

View File

@@ -39,10 +39,21 @@ namespace System.Net.Http
{
bytesRead = await readTask.ConfigureAwait(false);
}
#if MONOTOUCH_WATCH
catch (Exception exc)
{
if (CancellationHelper.ShouldWrapInOperationCanceledException(exc, cancellationToken))
{
throw CancellationHelper.CreateOperationCanceledException(exc, cancellationToken);
}
throw;
}
#else
catch (Exception exc) when (CancellationHelper.ShouldWrapInOperationCanceledException(exc, cancellationToken))
{
throw CancellationHelper.CreateOperationCanceledException(exc, cancellationToken);
}
#endif
finally
{
ctr.Dispose();
@@ -100,10 +111,21 @@ namespace System.Net.Http
{
await copyTask.ConfigureAwait(false);
}
#if MONOTOUCH_WATCH
catch (Exception exc)
{
if (CancellationHelper.ShouldWrapInOperationCanceledException(exc, cancellationToken))
{
throw CancellationHelper.CreateOperationCanceledException(exc, cancellationToken);
}
throw;
}
#else
catch (Exception exc) when (CancellationHelper.ShouldWrapInOperationCanceledException(exc, cancellationToken))
{
throw CancellationHelper.CreateOperationCanceledException(exc, cancellationToken);
}
#endif
finally
{
ctr.Dispose();

View File

@@ -51,10 +51,21 @@ namespace System.Net.Http
{
bytesRead = await readTask.ConfigureAwait(false);
}
#if MONOTOUCH_WATCH
catch (Exception exc)
{
if (CancellationHelper.ShouldWrapInOperationCanceledException(exc, cancellationToken))
{
throw CancellationHelper.CreateOperationCanceledException(exc, cancellationToken);
}
throw;
}
#else
catch (Exception exc) when (CancellationHelper.ShouldWrapInOperationCanceledException(exc, cancellationToken))
{
throw CancellationHelper.CreateOperationCanceledException(exc, cancellationToken);
}
#endif
finally
{
ctr.Dispose();
@@ -115,10 +126,21 @@ namespace System.Net.Http
{
await copyTask.ConfigureAwait(false);
}
#if MONOTOUCH_WATCH
catch (Exception exc)
{
if (CancellationHelper.ShouldWrapInOperationCanceledException(exc, cancellationToken))
{
throw CancellationHelper.CreateOperationCanceledException(exc, cancellationToken);
}
throw;
}
#else
catch (Exception exc) when (CancellationHelper.ShouldWrapInOperationCanceledException(exc, cancellationToken))
{
throw CancellationHelper.CreateOperationCanceledException(exc, cancellationToken);
}
#endif
finally
{
ctr.Dispose();

View File

@@ -158,11 +158,23 @@ namespace System.Net.Http
{
return _socket.Poll(0, SelectMode.SelectRead);
}
#if MONOTOUCH_WATCH
catch (Exception exc)
{
if (e is SocketException || e is ObjectDisposedException)
{
// Poll can throw when used on a closed socket.
return true;
}
throw;
}
#else
catch (Exception e) when (e is SocketException || e is ObjectDisposedException)
{
// Poll can throw when used on a closed socket.
return true;
}
#endif
}
else
{

View File

@@ -295,10 +295,24 @@ namespace System.Net.Http
{
return await SendWithNtConnectionAuthAsync((HttpConnection)connection, request, doRequestAuth, cancellationToken).ConfigureAwait(false);
}
#if MONOTOUCH_WATCH
catch (HttpRequestException e)
{
if (!isNewConnection && e.InnerException is IOException && connection.CanRetry)
{
// Eat exception and try again.
}
else
{
throw;
}
}
#else
catch (HttpRequestException e) when (!isNewConnection && e.InnerException is IOException && connection.CanRetry)
{
// Eat exception and try again.
}
#endif
finally
{
connection.Release();

View File

@@ -39,10 +39,21 @@ namespace System.Net.Http
{
bytesRead = await readTask.ConfigureAwait(false);
}
#if MONOTOUCH_WATCH
catch (Exception exc)
{
if (CancellationHelper.ShouldWrapInOperationCanceledException(exc, cancellationToken))
{
throw CancellationHelper.CreateOperationCanceledException(exc, cancellationToken);
}
throw;
}
#else
catch (Exception exc) when (CancellationHelper.ShouldWrapInOperationCanceledException(exc, cancellationToken))
{
throw CancellationHelper.CreateOperationCanceledException(exc, cancellationToken);
}
#endif
finally
{
ctr.Dispose();
@@ -95,10 +106,21 @@ namespace System.Net.Http
{
await copyTask.ConfigureAwait(false);
}
#if MONOTOUCH_WATCH
catch (Exception exc)
{
if (CancellationHelper.ShouldWrapInOperationCanceledException(exc, cancellationToken))
{
throw CancellationHelper.CreateOperationCanceledException(exc, cancellationToken);
}
throw;
}
#else
catch (Exception exc) when (CancellationHelper.ShouldWrapInOperationCanceledException(exc, cancellationToken))
{
throw CancellationHelper.CreateOperationCanceledException(exc, cancellationToken);
}
#endif
finally
{
ctr.Dispose();
@@ -168,10 +190,21 @@ namespace System.Net.Http
{
await task.ConfigureAwait(false);
}
#if MONOTOUCH_WATCH
catch (Exception exc)
{
if (CancellationHelper.ShouldWrapInOperationCanceledException(exc, cancellationToken))
{
throw CancellationHelper.CreateOperationCanceledException(exc, cancellationToken);
}
throw;
}
#else
catch (Exception exc) when (CancellationHelper.ShouldWrapInOperationCanceledException(exc, cancellationToken))
{
throw CancellationHelper.CreateOperationCanceledException(exc, cancellationToken);
}
#endif
finally
{
ctr.Dispose();

View File

@@ -56,5 +56,20 @@ namespace System.Net.Http.Tests
Assert.Equal(expectedResult, parameter != null);
}
[Theory]
[InlineData("test", "username=\"test\"")]
[InlineData("test@example.org", "username=\"test@example.org\"")]
[InlineData("test\"example.org", "username=\"test\\\"example.org\"")]
[InlineData("t\u00E6st", "username*=utf-8''t%C3%A6st")]
[InlineData("\uD834\uDD1E", "username*=utf-8''%F0%9D%84%9E")]
public async void DigestResponse_UserName_Encoding(string username, string encodedUserName)
{
NetworkCredential credential = new NetworkCredential(username, "bar");
AuthenticationHelper.DigestResponse digestResponse = new AuthenticationHelper.DigestResponse("realm=\"NetCore\", nonce=\"qMRqWgAAAAAQMjIABgAAAFwEiEwAAAAA\"");
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://microsoft.com/");
string parameter = await AuthenticationHelper.GetDigestTokenForCredential(credential, request, digestResponse).ConfigureAwait(false);
Assert.StartsWith(encodedUserName, parameter);
}
}
}

View File

@@ -12,10 +12,10 @@ namespace System.Net.Http.Tests
public class HttpContentTest
{
[Fact]
public void Dispose_BufferContentThenDisposeContent_BufferedStreamGetsDisposed()
public async Task Dispose_BufferContentThenDisposeContent_BufferedStreamGetsDisposed()
{
MockContent content = new MockContent();
content.LoadIntoBufferAsync().Wait();
await content.LoadIntoBufferAsync();
Type type = typeof(HttpContent);
TypeInfo typeInfo = type.GetTypeInfo();

View File

@@ -226,6 +226,7 @@ namespace System.Tests
}
[Fact]
[SkipOnTargetFramework(TargetFrameworkMonikers.Mono, "Flaky test - OOM")]
public static void ToString_ByteArrayTooLong_Throws()
{
byte[] arr;

View File

@@ -9,6 +9,24 @@ namespace System.Numerics.Tests
{
public partial class parseTest
{
[Theory]
[InlineData("123456789", 0, 9, "123456789")]
[InlineData("123456789", 0, 1, "1")]
[InlineData("123456789", 1, 3, "234")]
public void Parse_Subspan_Success(string input, int offset, int length, string expected)
{
Eval(BigInteger.Parse(input.AsSpan(offset, length)), expected);
Assert.True(BigInteger.TryParse(input.AsSpan(offset, length), out BigInteger test));
Eval(test, expected);
}
[Fact]
public void Parse_EmptySubspan_Fails()
{
Assert.False(BigInteger.TryParse("12345".AsSpan(0, 0), out BigInteger result));
Assert.Equal(0, result);
}
static partial void VerifyParseSpanToString(string num1, NumberStyles ns, bool failureNotExpected, string expected)
{
if (failureNotExpected)