From 67c2d1900850ff81fabc05317dee2717da00a77a Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Sat, 23 Sep 2023 21:11:09 +0200 Subject: [PATCH 1/2] Use invariant culture for CBOR tests --- .../src/System/Formats/Cbor/Reader/CborReader.Tag.cs | 4 ++-- .../src/System/Formats/Cbor/Writer/CborWriter.Tag.cs | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/libraries/System.Formats.Cbor/src/System/Formats/Cbor/Reader/CborReader.Tag.cs b/src/libraries/System.Formats.Cbor/src/System/Formats/Cbor/Reader/CborReader.Tag.cs index 238217856c190..91505d0b6561d 100644 --- a/src/libraries/System.Formats.Cbor/src/System/Formats/Cbor/Reader/CborReader.Tag.cs +++ b/src/libraries/System.Formats.Cbor/src/System/Formats/Cbor/Reader/CborReader.Tag.cs @@ -72,9 +72,9 @@ public DateTimeOffset ReadDateTimeOffset() string dateString = ReadTextString(); // TODO determine if conformance modes should allow inexact date sting parsing - if (!DateTimeOffset.TryParseExact(dateString, CborWriter.Rfc3339FormatString, null, DateTimeStyles.RoundtripKind, out DateTimeOffset result)) + if (!DateTimeOffset.TryParseExact(dateString, CborWriter.Rfc3339FormatString, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind, out DateTimeOffset result)) { - throw new CborContentException(SR.Cbor_Reader_InvalidDateTimeEncoding); + throw new CborContentException(SR.Cbor_Reader_InvalidDateTimeEncoding + " " + dateString); } return result; diff --git a/src/libraries/System.Formats.Cbor/src/System/Formats/Cbor/Writer/CborWriter.Tag.cs b/src/libraries/System.Formats.Cbor/src/System/Formats/Cbor/Writer/CborWriter.Tag.cs index e5e772dcfd1be..3ca04f085e04c 100644 --- a/src/libraries/System.Formats.Cbor/src/System/Formats/Cbor/Writer/CborWriter.Tag.cs +++ b/src/libraries/System.Formats.Cbor/src/System/Formats/Cbor/Writer/CborWriter.Tag.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; +using System.Globalization; using System.Numerics; namespace System.Formats.Cbor @@ -42,8 +43,8 @@ public void WriteDateTimeOffset(DateTimeOffset value) #else value.Offset == TimeSpan.Zero ? #endif // NET8_0_OR_GREATER - value.UtcDateTime.ToString(Rfc3339FormatString) : // prefer 'Z' over '+00:00' - value.ToString(Rfc3339FormatString); + value.UtcDateTime.ToString(Rfc3339FormatString, CultureInfo.InvariantCulture) : // prefer 'Z' over '+00:00' + value.ToString(Rfc3339FormatString, CultureInfo.InvariantCulture); WriteTag(CborTag.DateTimeString); WriteTextString(dateString); From 2c75b1515fc6af2dd2fde2627fa2feba6943589d Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Sat, 23 Sep 2023 21:19:24 +0200 Subject: [PATCH 2/2] Update src/libraries/System.Formats.Cbor/src/System/Formats/Cbor/Reader/CborReader.Tag.cs --- .../src/System/Formats/Cbor/Reader/CborReader.Tag.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Formats.Cbor/src/System/Formats/Cbor/Reader/CborReader.Tag.cs b/src/libraries/System.Formats.Cbor/src/System/Formats/Cbor/Reader/CborReader.Tag.cs index 91505d0b6561d..2dd4c4d1d9abe 100644 --- a/src/libraries/System.Formats.Cbor/src/System/Formats/Cbor/Reader/CborReader.Tag.cs +++ b/src/libraries/System.Formats.Cbor/src/System/Formats/Cbor/Reader/CborReader.Tag.cs @@ -74,7 +74,7 @@ public DateTimeOffset ReadDateTimeOffset() // TODO determine if conformance modes should allow inexact date sting parsing if (!DateTimeOffset.TryParseExact(dateString, CborWriter.Rfc3339FormatString, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind, out DateTimeOffset result)) { - throw new CborContentException(SR.Cbor_Reader_InvalidDateTimeEncoding + " " + dateString); + throw new CborContentException(SR.Cbor_Reader_InvalidDateTimeEncoding); } return result;