mangstadt / ez-vcard

A vCard parser library for Java
Other
398 stars 92 forks source link

Relaxed parsing for DATE values #102

Closed rfc2822 closed 4 years ago

rfc2822 commented 4 years ago

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)?

mangstadt commented 4 years ago

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?

rfc2822 commented 4 years ago

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

mangstadt commented 4 years ago

Fixed in b8102eac839352398422b70b8d53643bd043d3d1.

rfc2822 commented 4 years ago

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!

mangstadt commented 4 years ago

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