Commit 60e7b84
committed
Fix issues where code diverged from BCL behavior
Each polyfill below produced an observably different result from the
real .NET API it emulates; fixed to match the BCL, with a regression
test per bug that runs on both the polyfill (older TFMs) and the BCL
(newer TFMs).
Encoding / strings:
- Encoding.GetChars(ROS<byte>, Span<char>): copy only the decoded char
count instead of the whole scratch buffer (threw/clobbered on non-ASCII)
- string.ReplaceLineEndings: handle empty input, preserve a trailing
line ending, and recognise the full BCL set (FF/NEL/LS/PS)
- string.Join(char, ROS<string?>): treat null elements as empty (unsafe path)
- StringBuilder.Append(sb,int,int)/CopyTo: validate arguments
Date / time:
- DateTime/DateTimeOffset.AddMicroseconds: preserve sub-millisecond
precision via AddTicks (AddMilliseconds rounds on .NET Framework)
- DateTime/DateTimeOffset/TimeSpan Microsecond & Nanosecond: correct the
TicksPerMicrosecond constant (10, not 10,000,000) and the formula
- TimeSpan.FromDays/Hours/Minutes/Seconds/Milliseconds/Microseconds:
throw ArgumentOutOfRangeException on overflow, accumulating in
microseconds (decimal) so cancelling components stay in range
Collections / spans:
- Span.Sort(keys, values, Comparison): pass null keys to the comparison
- ConcurrentDictionary.GetOrAdd: validate valueFactory
- List.CopyTo(Span)/InsertRange: validate destination length / index
- EqualityComparer.Create: validate the delegate
Numbers / Convert:
- double/float.TryParse(.., provider, ..): include NumberStyles.AllowThousands
(the BCL default) in the default-style overloads
- Convert.FromHexString (both OperationStatus overloads): correct
charsConsumed on invalid data and give DestinationTooSmall priority
- ArgumentOutOfRangeException.ThrowIfZero: set ActualValue and message;
fix two nint relational message strings
Reflection:
- Type.GetMethod(name, genericParameterCount, ..): argument validation
- MemberInfo.HasSameMetadataDefinitionAs(null): throw ArgumentNullException
IO / XML / compression / crypto / async:
- File.GetUnixFileMode/SetUnixFileMode: correct setuid(4)/setgid(2) mapping
- XDocument/XElement.LoadAsync(Stream): honor the XML-declared encoding
instead of forcing UTF-8
- ZipFile.ExtractToDirectoryAsync(overwriteFiles:true): overwrite per file
instead of deleting the whole destination directory
- RandomNumberGenerator.GetInt32: off-by-one rejection that never returned
the maximum value
- TaskCompletionSource.TrySetCanceled(token): forward the token
- ZLibStream: document that the Adler-32 trailer is not validated1 parent 7ea1e86 commit 60e7b84
433 files changed
Lines changed: 4776 additions & 2046 deletions
File tree
- src
- Polyfill
- ArgumentExceptions
- Numbers
- Split
- net10.0
- net11.0
- net461
- ArgumentExceptions
- Numbers
- net462
- ArgumentExceptions
- Numbers
- net471
- ArgumentExceptions
- Numbers
- net472
- ArgumentExceptions
- Numbers
- net47
- ArgumentExceptions
- Numbers
- net481
- ArgumentExceptions
- Numbers
- net48
- ArgumentExceptions
- Numbers
- net5.0
- ArgumentExceptions
- Numbers
- net6.0
- ArgumentExceptions
- Numbers
- net7.0
- ArgumentExceptions
- Numbers
- net8.0
- net9.0
- netcoreapp2.0
- ArgumentExceptions
- Numbers
- netcoreapp2.1
- ArgumentExceptions
- Numbers
- netcoreapp2.2
- ArgumentExceptions
- Numbers
- netcoreapp3.0
- ArgumentExceptions
- Numbers
- netcoreapp3.1
- ArgumentExceptions
- Numbers
- netstandard2.0
- ArgumentExceptions
- Numbers
- netstandard2.1
- ArgumentExceptions
- Numbers
- uap10.0
- ArgumentExceptions
- Numbers
- Tests
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
52 | 52 | | |
0 commit comments