collective / icalendar

icalendar parser library for Python
https://icalendar.readthedocs.io/en/latest/
Other
982 stars 169 forks source link

Support DQUOTE character in property parameter values #219

Open WhyNotHugo opened 7 years ago

WhyNotHugo commented 7 years ago

Parsing this [apparently] valid file fails/crashes:

BEGIN:VCALENDAR
CALSCALE:GREGORIAN
PRODID:-//Apple Inc.//iOS 10.2.1//EN
VERSION:2.0
BEGIN:VTODO
COMPLETED:20170312T122019Z
CREATED:20170312T051318Z
DTSTAMP:20170312T122023Z
LAST-MODIFIED:20170312T122021Z
PERCENT-COMPLETE:100
PRIORITY:1
SEQUENCE:0
STATUS:COMPLETED
SUMMARY:Cosas en el freezer
UID:5ACD2904-D0CE-4097-BC75-C1EB95C0BB22
X-APPLE-SORT-ORDER:510988398
BEGIN:VALARM
ACKNOWLEDGED:20170312T122015Z
ACTION:DISPLAY
DESCRIPTION:Reminder
TRIGGER;VALUE=DATE-TIME:19760401T005545Z
UID:E13840A6-C30C-4BF0-A3E1-73EF27E34BD9
X-APPLE-PROXIMITY:ARRIVE
X-APPLE-STRUCTURED-LOCATION;VALUE=URI;X-ADDRESS=Ayacucho 983\\nPlata Baja 
 \"A\"\\nC1111AAC CABA\\nArgentina\\nArgentina;X-APPLE-ABUID="ab://Home";
 X-APPLE-RADIUS=0;X-APPLE-REFERENCEFRAME=1;X-TITLE=Home:geo:
 -34.597613,-58.395858
X-WR-ALARMUID:E13840A6-C30C-4BF0-A3E1-73EF27E34BD9
END:VALARM
END:VTODO
END:VCALENDAR

Traceback:

Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/icalendar/parser.py", line 241, in from_ical
    validate_param_value(v, quoted=False)
  File "/usr/lib/python3.6/site-packages/icalendar/parser.py", line 132, in validate_param_value
    raise ValueError(value)
ValueError: Ayacucho 983%5CnPlata Baja \"A\"%5CnC1111AAC CABA%5CnArgentina%5CnArgentina

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/icalendar/parser.py", line 336, in parts
    strict=self.strict)
  File "/usr/lib/python3.6/site-packages/icalendar/parser.py", line 255, in from_ical
    % (param, exc))
ValueError: 'X-ADDRESS=Ayacucho 983%5CnPlata Baja \\"A\\"%5CnC1111AAC CABA%5CnArgentina%5CnArgentina' is not a valid parameter string: Ayacucho 983%5CnPlata Baja \"A\"%5CnC1111AAC
 CABA%5CnArgentina%5CnArgentina

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/todoman/model.py", line 799, in update_cache
    todo = FileTodo.from_file(entry_path)
  File "/usr/lib/python3.6/site-packages/todoman/model.py", line 309, in from_file
    cal = icalendar.Calendar.from_ical(cal)
  File "/usr/lib/python3.6/site-packages/icalendar/cal.py", line 330, in from_ical
    name, params, vals = line.parts()
  File "/usr/lib/python3.6/site-packages/icalendar/parser.py", line 346, in parts
    % (self, exc)
ValueError: Content line could not be parsed into parts: 'X-APPLE-STRUCTURED-LOCATION;VALUE=URI;X-ADDRESS=Ayacucho 983\\nPlata Baja \"A\"\\nC1111AAC CABA\\nArgentina\\nArgentina;X-APPLE-ABUID="ab://Home";X-APPLE-RADIUS=0;X-APPLE-REFERENCEFRAME=1;X-TITLE=Home:geo:-34.597613,-58.395858': 'X-ADDRESS=Ayacucho 983%5CnPlata Baja \\"A\\"%5CnC1111AAC CABA%5CnArgen
tina%5CnArgentina' is not a valid parameter string: Ayacucho 983%5CnPlata Baja \"A\"%5CnC1111AAC CABA%5CnArgentina%5CnArgentina
WhyNotHugo commented 7 years ago

This may be related to #197, but I don't think this is binary data (is it?).

geier commented 7 years ago

Try https://github.com/collective/icalendar/pull/207 and see if it's gone.

WhyNotHugo commented 7 years ago

Nope, exact same error with that branch. :(

geier commented 7 years ago

The problem here are the quoted " around the A, by my reading of the RFC, Ayacucho 983\\nPlata Baja \"A\"\\nC1111AAC CABA\\nArgentina\\nArgentina is a property parameter and as the RFC states Property parameter values MUST NOT contain the DQUOTE character, this is not a valid icalendar file. If you can reproduce this, I you might want to file a bug with apple.

WhyNotHugo commented 7 years ago

Ugh, yes, it's trivial to reproduce. I'll open up an issue there.

In the meantime, I wonder if we can skip unknown lines and parse the rest. At least then lines start with X-.

There'd have to be some way to inform of the mis-parse to the end-user though. Maybe a flag when parsing to actually enable this behaviour?