From 2ab5c5385e80d4cbfe64878ef38283d008471e04 Mon Sep 17 00:00:00 2001 From: Steve Molloy Date: Thu, 4 Sep 2025 23:16:47 -0700 Subject: [PATCH 1/2] Add test coverage for issue #99193 --- ...stem.ServiceModel.Syndication.Tests.csproj | 1 + .../Syndication/Rfc822DateParsingTests.cs | 60 +++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 src/libraries/System.ServiceModel.Syndication/tests/System/ServiceModel/Syndication/Rfc822DateParsingTests.cs diff --git a/src/libraries/System.ServiceModel.Syndication/tests/System.ServiceModel.Syndication.Tests.csproj b/src/libraries/System.ServiceModel.Syndication/tests/System.ServiceModel.Syndication.Tests.csproj index 1d2c8ab02e08a9..df1cce5db2c3fb 100644 --- a/src/libraries/System.ServiceModel.Syndication/tests/System.ServiceModel.Syndication.Tests.csproj +++ b/src/libraries/System.ServiceModel.Syndication/tests/System.ServiceModel.Syndication.Tests.csproj @@ -11,6 +11,7 @@ + diff --git a/src/libraries/System.ServiceModel.Syndication/tests/System/ServiceModel/Syndication/Rfc822DateParsingTests.cs b/src/libraries/System.ServiceModel.Syndication/tests/System/ServiceModel/Syndication/Rfc822DateParsingTests.cs new file mode 100644 index 00000000000000..34ff0499968cea --- /dev/null +++ b/src/libraries/System.ServiceModel.Syndication/tests/System/ServiceModel/Syndication/Rfc822DateParsingTests.cs @@ -0,0 +1,60 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.IO; +using System.Xml; +using Xunit; +using System.Globalization; + +namespace System.ServiceModel.Syndication.Tests +{ + public class Rfc822DateParsingTests + { + [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)] // NetFx requires double digit dates and four digit years + [Theory] + [InlineData("Mon, 2 Jun 2003 09:39:21 GMT", 2003, 6, 2, 9, 39, 21)] + [InlineData("2 Jun 2003 09:39:21 GMT", 2003, 6, 2, 9, 39, 21)] + [InlineData("02 Jun 03 09:39:21 GMT", 2003, 6, 2, 9, 39, 21)] + [InlineData("Mon, 2 Jun 03 09:39:21 GMT", 2003, 6, 2, 9, 39, 21)] + [InlineData("2 Jun 03 09:39 GMT", 2003, 6, 2, 9, 39, 0)] + [InlineData("02 Jun 03 09:39 GMT", 2003, 6, 2, 9, 39, 0)] + [InlineData("Mon, 2 Jun 03 09:39 GMT", 2003, 6, 2, 9, 39, 0)] + [InlineData("Mon, 02 Jun 03 09:39 GMT", 2003, 6, 2, 9, 39, 0)] + // As of .Net 8.0, CultureInfo.CurrentCulture.DateTimeFormat.Calendar.TwoDigitYearMax is 2049 for invariant and en-US cultures + [InlineData("2 Jun 50 09:39 GMT", 1950, 6, 2, 9, 39, 0)] + [InlineData("2 Jun 49 09:39 GMT", 2049, 6, 2, 9, 39, 0)] + public void Rss20ItemFormatter_Read_SingleDigitDay_And_TwoDigitYear(string pubDate, int year, int month, int day, int hour, int minute, int second) + { + string xml = $"{pubDate}"; + using var stringReader = new StringReader(xml); + using var reader = XmlReader.Create(stringReader); + var formatter = new Rss20ItemFormatter(); + formatter.ReadFrom(reader); + DateTimeOffset expected = new DateTimeOffset(year, month, day, hour, minute, second, TimeSpan.Zero); + Assert.Equal(expected, formatter.Item.PublishDate); + } + + [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)] // NetFx requires double digit dates and four digit years + [Theory] + [InlineData("Mon, 2 Jun 2003 09:39:21 +0000", 2003, 6, 2, 9, 39, 21)] + [InlineData("Mon, 2 Jun 2003 09:39:21 -0000", 2003, 6, 2, 9, 39, 21)] + [InlineData("Mon, 2 Jun 2003 09:39:21 UT", 2003, 6, 2, 9, 39, 21)] + [InlineData("Mon, 02 Jun 03 09:39:21 +0000", 2003, 6, 2, 9, 39, 21)] + [InlineData("Mon, 02 Jun 03 09:39:21 -0000", 2003, 6, 2, 9, 39, 21)] + [InlineData("Mon, 02 Jun 03 09:39:21 UT", 2003, 6, 2, 9, 39, 21)] + // As of .Net 8.0, CultureInfo.CurrentCulture.DateTimeFormat.Calendar.TwoDigitYearMax is 2049 for invariant and en-US cultures + [InlineData("02 Jun 50 09:39:21 +0000", 1950, 6, 2, 9, 39, 21)] + [InlineData("02 Jun 50 09:39:21 -0000", 1950, 6, 2, 9, 39, 21)] + [InlineData("02 Jun 49 09:39:21 UT", 2049, 6, 2, 9, 39, 21)] + public void Rss20ItemFormatter_Read_SingleDigitDay_NormalizedTimeZones(string pubDate, int year, int month, int day, int hour, int minute, int second) + { + string xml = $"{pubDate}"; + using var stringReader = new StringReader(xml); + using var reader = XmlReader.Create(stringReader); + var formatter = new Rss20ItemFormatter(); + formatter.ReadFrom(reader); + DateTimeOffset expectedUtc = new DateTimeOffset(year, month, day, hour, minute, second, TimeSpan.Zero); + Assert.Equal(expectedUtc, formatter.Item.PublishDate); + } + } +} From ee684e9ee8e3bf67119bfb222b4376907ec5aa1a Mon Sep 17 00:00:00 2001 From: Steve Molloy Date: Wed, 24 Sep 2025 22:50:45 -0700 Subject: [PATCH 2/2] Make two-digit year boundary test more resilient to changes in DateTimeFormat.Calendar.TwoDigitYearMax --- .../Syndication/Rfc822DateParsingTests.cs | 42 ++++++++++++++----- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/src/libraries/System.ServiceModel.Syndication/tests/System/ServiceModel/Syndication/Rfc822DateParsingTests.cs b/src/libraries/System.ServiceModel.Syndication/tests/System/ServiceModel/Syndication/Rfc822DateParsingTests.cs index 34ff0499968cea..4064c35a8916e4 100644 --- a/src/libraries/System.ServiceModel.Syndication/tests/System/ServiceModel/Syndication/Rfc822DateParsingTests.cs +++ b/src/libraries/System.ServiceModel.Syndication/tests/System/ServiceModel/Syndication/Rfc822DateParsingTests.cs @@ -20,9 +20,6 @@ public class Rfc822DateParsingTests [InlineData("02 Jun 03 09:39 GMT", 2003, 6, 2, 9, 39, 0)] [InlineData("Mon, 2 Jun 03 09:39 GMT", 2003, 6, 2, 9, 39, 0)] [InlineData("Mon, 02 Jun 03 09:39 GMT", 2003, 6, 2, 9, 39, 0)] - // As of .Net 8.0, CultureInfo.CurrentCulture.DateTimeFormat.Calendar.TwoDigitYearMax is 2049 for invariant and en-US cultures - [InlineData("2 Jun 50 09:39 GMT", 1950, 6, 2, 9, 39, 0)] - [InlineData("2 Jun 49 09:39 GMT", 2049, 6, 2, 9, 39, 0)] public void Rss20ItemFormatter_Read_SingleDigitDay_And_TwoDigitYear(string pubDate, int year, int month, int day, int hour, int minute, int second) { string xml = $"{pubDate}"; @@ -36,16 +33,9 @@ public void Rss20ItemFormatter_Read_SingleDigitDay_And_TwoDigitYear(string pubDa [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)] // NetFx requires double digit dates and four digit years [Theory] - [InlineData("Mon, 2 Jun 2003 09:39:21 +0000", 2003, 6, 2, 9, 39, 21)] - [InlineData("Mon, 2 Jun 2003 09:39:21 -0000", 2003, 6, 2, 9, 39, 21)] - [InlineData("Mon, 2 Jun 2003 09:39:21 UT", 2003, 6, 2, 9, 39, 21)] [InlineData("Mon, 02 Jun 03 09:39:21 +0000", 2003, 6, 2, 9, 39, 21)] [InlineData("Mon, 02 Jun 03 09:39:21 -0000", 2003, 6, 2, 9, 39, 21)] [InlineData("Mon, 02 Jun 03 09:39:21 UT", 2003, 6, 2, 9, 39, 21)] - // As of .Net 8.0, CultureInfo.CurrentCulture.DateTimeFormat.Calendar.TwoDigitYearMax is 2049 for invariant and en-US cultures - [InlineData("02 Jun 50 09:39:21 +0000", 1950, 6, 2, 9, 39, 21)] - [InlineData("02 Jun 50 09:39:21 -0000", 1950, 6, 2, 9, 39, 21)] - [InlineData("02 Jun 49 09:39:21 UT", 2049, 6, 2, 9, 39, 21)] public void Rss20ItemFormatter_Read_SingleDigitDay_NormalizedTimeZones(string pubDate, int year, int month, int day, int hour, int minute, int second) { string xml = $"{pubDate}"; @@ -56,5 +46,37 @@ public void Rss20ItemFormatter_Read_SingleDigitDay_NormalizedTimeZones(string pu DateTimeOffset expectedUtc = new DateTimeOffset(year, month, day, hour, minute, second, TimeSpan.Zero); Assert.Equal(expectedUtc, formatter.Item.PublishDate); } + + [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)] // NetFx requires double digit dates and four digit years + [Theory] + [InlineData("2 Jun {year} 09:39 GMT", 6, 2, 9, 39, 0)] + [InlineData("02 Jun {year} 09:39:21 +0000", 6, 2, 9, 39, 21)] + [InlineData("02 Jun {year} 09:39:21 -0000", 6, 2, 9, 39, 21)] + [InlineData("02 Jun {year} 09:39:21 UT", 6, 2, 9, 39, 21)] + public void Rss20ItemFormatter_Read_SingleDigitDay_And_TwoDigitYear_Max(string pubDate, int month, int day, int hour, int minute, int second) + { + // As of .Net 8.0, CultureInfo.CurrentCulture.DateTimeFormat.Calendar.TwoDigitYearMax is 2049 for invariant and en-US cultures + var maxDate = CultureInfo.CurrentCulture.DateTimeFormat.Calendar.TwoDigitYearMax % 100; + + // Test under/at the 2-digit year max threshold + var underDate = pubDate.Replace("{year}", maxDate.ToString()); + string xml = $"{underDate}"; + using var stringReader = new StringReader(xml); + using var reader = XmlReader.Create(stringReader); + var formatter = new Rss20ItemFormatter(); + formatter.ReadFrom(reader); + DateTimeOffset expectedUnder = new DateTimeOffset(2000 + maxDate, month, day, hour, minute, second, TimeSpan.Zero); + Assert.Equal(expectedUnder, formatter.Item.PublishDate); + + // Test over the 2-digit year max threshold + var overDate = pubDate.Replace("{year}", (maxDate + 1).ToString()); + xml = $"{overDate}"; + using var stringReaderOver = new StringReader(xml); + using var readerOver = XmlReader.Create(stringReaderOver); + formatter = new Rss20ItemFormatter(); + formatter.ReadFrom(readerOver); + DateTimeOffset expectedOver = new DateTimeOffset(1900 + maxDate + 1, month, day, hour, minute, second, TimeSpan.Zero); + Assert.Equal(expectedOver, formatter.Item.PublishDate); + } } }