u01jmg3 / ics-parser

Parser for iCalendar Events • PHP 8+, 7 (≥ 7.4), 5 (≥ 5.6)
MIT License
448 stars 144 forks source link

Modification of ICal/keyValueFromString to match RFC5545 #290

Closed noec764 closed 2 years ago

noec764 commented 2 years ago

I change this function because of a unexpected behaviour.

Indeed, I have this line in my ics file :

ATTENDEE;CN="Lieu : Laboratoire Dép. d'Analyse, Bâtiment : Laboratoire Dép. d'Analyse, Étage : 0, Salle : Grande salle";CUTYPE=RESOURCE;ROLE=NON-PARTICIPANT;PARTSTAT=ACCEPTED;RSVP=TRUE:mailto:xxx@xxx.fr

but when it was parsed by keyValueFromString function I get this result:

Array (size=2) 0 => string 'ATTENDEE' (length=8) 1 => array (size=2) 0 => string 'mailto:xxx@xxx.fr (length=40) 1 => array (size=1) 'CN' => string 'Lieu: Laboratoire Dép. d'Analyse, Bâtiment: Laboratoire Dép. d'Analyse, Étage: 0, Salle: Grande salle;CUTYPE' (length=112)

We can see that there is no more CUTYPE , ROLE, PARTSTAT and RSVP parameters.

I found out that this function doesn't parse ics line as recommended in RFC5545 especially when using str_getcsv($text, ':') which explodes strings on colon even inside double quote.

I finally decides to re code this function entirely in order respect the RFC5545.

The parseLine() function analyses the line characters by characters and return a array of strings and separators.

Then the keyValueFromString() create the object corresponding to what is expected in RFC5545 and matching with old function template.