Skip to content

Conversation

@dougwaldron
Copy link
Contributor

RFC822 allows single-digit date values and two-digit year values in the publication date (pubDate). The existing Rfc822DateTimeParser method in System.ServiceModel.Syndication.DateTimeHelper only accepts two-digit dates and (for some formats) four-digit years.

This PR updates the list of date-time formats.

Fixes #99193

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.
@dougwaldron
Copy link
Contributor Author

Any chance on getting this merged for .NET 9?

@dougwaldron
Copy link
Contributor Author

Any chance of getting this merged for 9.0.2?

This is very simple fix for a bug caused by a small typo. There is almost zero risk to merging this, and it would fix a bug that has existed in my application for a year now.

@stephentoub stephentoub requested a review from Copilot May 28, 2025 18:13
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the date-time format patterns in the RFC822 parser to correctly handle single-digit day values and two-digit year values as per the RFC822 specification.

  • Updated date format strings to use "d" instead of "dd" for days.
  • Adjusted both the time formats with seconds and without seconds to support the new behavior.
Comments suppressed due to low confidence (2)

src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/DateTimeHelper.cs:95

  • Ensure that unit tests cover the new date-time formats, particularly for cases with single-digit day values and two-digit years.
"ddd, d MMMM yyyy HH:mm:ss zzz",

src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/DateTimeHelper.cs:105

  • [nitpick] Consider reviewing the ordering of the format patterns to ensure that the most frequently encountered date formats are prioritized for optimal performance.
// 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.

Copy link
Member

@StephenMolloy StephenMolloy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@StephenMolloy
Copy link
Member

@dotnet-policy-service rerun

@StephenMolloy
Copy link
Member

/azp run runtime

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@StephenMolloy
Copy link
Member

Thanks @dougwaldron! This is a solid improvement that brings our RSS date handling closer to the intent of RFC 822 while keeping the existing layered fallback behavior.

For anyone following along: the current RSS date parsing path (see the internal helper in System.ServiceModel.Syndication) tries, in order:

  1. A straight DateTimeOffset.TryParse(...) on the raw string (to catch many already-well‑formed or framework-supported variants)
  2. An RFC 822–style parse (normalizing the time zone token before parsing)
  3. An RFC 3339 (Atom-style) parse as a pragmatic fallback (since feeds in the wild often mix styles)

That balance lets us stay compliant yet resilient. This PR tightens conformance in the RFC 822 layer without removing the practical fallbacks.

Reminder: If you encounter feeds whose date strings are even more “creative” (e.g., ordinal day tokens, missing commas, non-English month names, 2‑digit years, or embedded comments), you do NOT have to push further loosening into the core library. You can plug in your own parsing logic via the public delegate hook:

using System;
using System.ServiceModel.Syndication;

// Do this once early in app startup (before loading feeds).
// Capture the existing parser so you can chain/fallback.
var originalRssParser = Rss20FeedFormatter.DateTimeParser;

// Install a custom parser
Rss20FeedFormatter.DateTimeParser = (xmlDateTimeData, out DateTimeOffset dto) =>
{
    // xmlDateTimeData.DateTimeString is the raw value.
    // Return true if you successfully parsed; set dto accordingly.

    if (MyVeryForgivingParser(xmlDateTimeData.DateTimeString, out dto))
    {
        return true;
    }

    // Fall back to the framework’s (now improved) default behavior
    return originalRssParser(xmlDateTimeData, out dto);
};

// Example custom routine (simplified)
static bool MyVeryForgivingParser(string s, out DateTimeOffset dto)
{
    // Your heuristics here (strip ordinal suffixes, normalize TZ tokens, etc.)
    // Return true on success.
    dto = default;
    return false;
}

(Atom feeds have an analogous hook via Atom10FeedFormatter.DateTimeParser.)

A few tips when customizing:

  • Keep your parser narrowly scoped: only handle the truly outlier patterns you see.
  • Chain to the original so you inherit spec-aligned improvements like the one in this PR.
  • If you need per-feed experimentation, you can temporarily swap the delegate, parse, then restore it—but prefer a stable global install to avoid races.

Given the clear standards improvement and low risk, I’m proceeding with the merge. Thanks again for tightening this up and helping the ecosystem stay closer to the spec while still allowing extensibility.

@StephenMolloy StephenMolloy merged commit f0fa94f into dotnet:main Sep 19, 2025
67 checks passed
@StephenMolloy
Copy link
Member

/backport to release/10.0

@github-actions
Copy link
Contributor

Started backporting to release/10.0: https://github.com/dotnet/runtime/actions/runs/17871053134

xtqqczze pushed a commit to xtqqczze/dotnet-runtime that referenced this pull request Sep 20, 2025
* 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.

* Remove trailing whitespace in parseFormat array
@github-actions github-actions bot locked and limited conversation to collaborators Oct 20, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The Syndication DateTimeHelper class throws an exception on some valid RFC822 dates

3 participants