mangstadt/ez-vcard

Relaxed parsing for DATE values

Closed this issue · 5 comments

Hi,

We recently found that a (quite common) CardDAV server serves vCards like this one:

BEGIN:VCARD 
VERSION:3.0
…
BDAY:2020-4-1

(note the wrong date syntax without leading zeroes)

This is parsed as a RawProperty by ez-vcard, and not as Birthday as one may expect. We will report this to the server vendor, of course.

However, would it be possible to apply some kind of relaxed parsing so that month and day values without leading zero are detected and assigned to the original property (in this case, Birthday instead of RawProperty)?

It looks I should be able to add support for this particular date format without breaking anything.

The fix would involve changing the date parsing regex from
(\\d{4})-?(\\d{2})-?(\\d{2})
to
(\\d{4})-?(\\d{1,2})-?(\\d{1,2})

However, if the hyphens are removed, this can create ambiguity (some vCard versions do not use hyphens in their dates).

For example:

2020-1-13 : We know this is Jan 13
2020113 : Is this Jan 13 or Nov 3?

Yes, I guess it would only be applicable to the format with hyphens. The supposed change of the regex sounds very good to me :)

Fixed in b8102ea.

Thanks! :)

The server vendor has already said that they will fix the format on their side, too, but I think it will increase compatibility nevertheless!

Ah, that's good to hear. Yes, this will make ez-vcard a bit more flexible!