Description
Description
When the System.ServiceModel.Syndication
library parses feed item publication dates with single-digit dates (e.g., "7 Jun 2023") or double-digit years (for some date-time formats), an exception is thrown even though the date is valid.
The RSS 2.0 spec specifies that pubDate
should conform to RFC 822 except that "the year may be expressed with two characters or four characters (four preferred)." And RFC 822 specifies that the date portion of the date-time value may be 1 or 2 digits.
Reproduction Steps
The RSS feed for The Talk Show uses single-digit dates (for example, episode 378). When this feed is loaded as a SyndicationFeed
, the PublishDate
for that episode throws an exception.
Expected behavior
Valid dates should be parsed correctly without throwing an exception.
Actual behavior
Parsing a feed with valid single-digit dates returns an exception message, "An error was encountered when parsing a DateTime value in the XML."
Regression?
This bug has existed since at least 2017.
Known Workarounds
There is no workaround. The list of date parsing formats is inside a private method, and once the feed is parsed, the original feed item date is not retained.
Configuration
No response
Other information
The Rfc822DateTimeParser
method uses DateTimeOffset.TryParseExact
with an array of possible date formats intended to be based on RFC 822. But the list of formats only accepts 2-digit dates. This can easily be fixed.
Also, the comments in that method imply that 2-digit years are to be accepted, but some of the intended 2-digit year formats still require 4-digit years. This appears to be a copy/paste error.
I have a pull request ready to go.