From 218d8cb53bd22d536711e88ea7c3a348a4541f45 Mon Sep 17 00:00:00 2001 From: Doug Waldron <737326+dougwaldron@users.noreply.github.com> Date: Sat, 2 Mar 2024 15:23:12 -0500 Subject: [PATCH 1/2] Fix the Syndication RFC822 DateTimeParser RFC822 allows single-digit date values and two-digit year values in the publication date (pubDate). The existing date-time parser only accepted two-digit dates and (for some formats) four-digit years. --- .../Syndication/DateTimeHelper.cs | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/DateTimeHelper.cs b/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/DateTimeHelper.cs index b9b6cada89d568..645105aefbf777 100644 --- a/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/DateTimeHelper.cs +++ b/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/DateTimeHelper.cs @@ -92,28 +92,28 @@ private static bool Rfc822DateTimeParser(string dateTimeString, out DateTimeOffs DateTimeOffset theTime; string[] parseFormat = { - "ddd, dd MMMM yyyy HH:mm:ss zzz", - "dd MMMM yyyy HH:mm:ss zzz", - "ddd, dd MMM yyyy HH:mm:ss zzz", - "dd MMM yyyy HH:mm:ss zzz", - - "ddd, dd MMMM yyyy HH:mm zzz", - "dd MMMM yyyy HH:mm zzz", - "ddd, dd MMM yyyy HH:mm zzz", - "dd MMM yyyy HH:mm zzz", - + "ddd, d MMMM yyyy HH:mm:ss zzz", + "d MMMM yyyy HH:mm:ss zzz", + "ddd, d MMM yyyy HH:mm:ss zzz", + "d MMM yyyy HH:mm:ss zzz", + + "ddd, d MMMM yyyy HH:mm zzz", + "d MMMM yyyy HH:mm zzz", + "ddd, d MMM yyyy HH:mm zzz", + "d MMM yyyy HH:mm zzz", + // The original RFC822 spec listed 2 digit years. RFC1123 updated the format to include 4 digit years and states that you should use 4 digits. // Technically RSS2.0 specifies RFC822 but it's presumed that RFC1123 will be used as we're now past Y2K and everyone knows better. The 4 digit // formats are listed first for performance reasons as it's presumed they will be more likely to match first. - "ddd, dd MMMM yy HH:mm:ss zzz", - "dd MMMM yyyy HH:mm:ss zzz", - "ddd, dd MMM yy HH:mm:ss zzz", - "dd MMM yyyy HH:mm:ss zzz", - - "ddd, dd MMMM yy HH:mm zzz", - "dd MMMM yyyy HH:mm zzz", - "ddd, dd MMM yy HH:mm zzz", - "dd MMM yyyy HH:mm zzz" + "ddd, d MMMM yy HH:mm:ss zzz", + "d MMMM yy HH:mm:ss zzz", + "ddd, d MMM yy HH:mm:ss zzz", + "d MMM yy HH:mm:ss zzz", + + "ddd, d MMMM yy HH:mm zzz", + "d MMMM yy HH:mm zzz", + "ddd, d MMM yy HH:mm zzz", + "d MMM yy HH:mm zzz" }; if (DateTimeOffset.TryParseExact(wellFormattedString, parseFormat, From cbfa4dae9178009e48ae28a8bfc90a1a938757a1 Mon Sep 17 00:00:00 2001 From: Doug Waldron Date: Sat, 2 Mar 2024 19:16:57 -0500 Subject: [PATCH 2/2] Remove trailing whitespace in parseFormat array --- .../src/System/ServiceModel/Syndication/DateTimeHelper.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/DateTimeHelper.cs b/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/DateTimeHelper.cs index 645105aefbf777..ac40b68bf01778 100644 --- a/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/DateTimeHelper.cs +++ b/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/DateTimeHelper.cs @@ -96,12 +96,12 @@ private static bool Rfc822DateTimeParser(string dateTimeString, out DateTimeOffs "d MMMM yyyy HH:mm:ss zzz", "ddd, d MMM yyyy HH:mm:ss zzz", "d MMM yyyy HH:mm:ss zzz", - + "ddd, d MMMM yyyy HH:mm zzz", "d MMMM yyyy HH:mm zzz", "ddd, d MMM yyyy HH:mm zzz", "d MMM yyyy HH:mm zzz", - + // The original RFC822 spec listed 2 digit years. RFC1123 updated the format to include 4 digit years and states that you should use 4 digits. // Technically RSS2.0 specifies RFC822 but it's presumed that RFC1123 will be used as we're now past Y2K and everyone knows better. The 4 digit // formats are listed first for performance reasons as it's presumed they will be more likely to match first. @@ -109,7 +109,7 @@ private static bool Rfc822DateTimeParser(string dateTimeString, out DateTimeOffs "d MMMM yy HH:mm:ss zzz", "ddd, d MMM yy HH:mm:ss zzz", "d MMM yy HH:mm:ss zzz", - + "ddd, d MMMM yy HH:mm zzz", "d MMMM yy HH:mm zzz", "ddd, d MMM yy HH:mm zzz",