EWSoftware / PDI

A Personal Data Interchange (PDI) library that implements the vCard (RFC 2426), vCalendar, and iCalendar (RFC 2445) specifications including recurrence pattern generation
Microsoft Public License
64 stars 26 forks source link

Recurrence Custom Properties Not Parsed #1

Closed bchavez closed 9 years ago

bchavez commented 9 years ago

Hi,

I'm really happy to see PDI open-sourced now. I bought a PDI license long-long ago.

So, I've migrated some legacy code to use the NuGet lib and have a couple of unit tests that are failing.

In particular, I noticed Recurrence.ToStringWithStartDateTime() includes custom properties into the recurrence rule. However, creating a new recurrence (from the original serialization) won't include the custom properties. For example, the following unit test fails:

var source = new Recurrence
    {
        StartDateTime = DateTime.Parse("1/1/2008 4:30 AM"),
        RecurUntil = DateTime.Parse("1/5/2008 5:30 AM")
    };
source.RecurDaily( 1 );

source.CustomProperties.Add("hello");

var ruleAsString = source.ToStringWithStartDateTime();
Console.WriteLine( ruleAsString );
//FREQ=DAILY;UNTIL=20080105T133000Z;hello;X-EWSOFTWARE-DTSTART=20080101T123000Z

var target = new Recurrence( ruleAsString );

target.CustomProperties.Count.Should().Be(1);
//Expected 1, but found 0.

I'd be happy to send you a pull request that fixes the issue. Thanks!

EWSoftware commented 9 years ago

Although not enforced when adding them, custom properties are expected to be in the form "X-NAME=Value" per the specification. Since a name alone without a value doesn't conform to what is being parsed, it does end up being ignored. It can be extended to support non-standard properties that are names alone so if you've got a patch, I can merge it.

bchavez commented 9 years ago

Ah yes, thank you. The unit test is passing now with "X-NAME=Value". I should have looked more closely at the parsing method. Sorry I missed that. It's probably okay the way it is currently. Thanks Eric.