mangstadt / biweekly

biweekly is an iCalendar library written in Java.
BSD 2-Clause "Simplified" License
323 stars 44 forks source link

Parse errors (or lack thereof) #60

Closed jjl closed 7 years ago

jjl commented 7 years ago

When I try to run the readme reader code but put in leading spacing on the string literal, rather than an error as I expected, I simply get an empty collection.

I'm not sure if parse is supposed to be able to handle arbitrary streams, but it seems desirable that it throws an error if it gets a malformed stream. Thoughts?

jjl commented 7 years ago

Reproduction case (clojure):

(def t
"BEGIN:VCALENDAR\r
  VERSION:2.0\r
  PRODID:-//Microsoft Corporation//Outlook 14.0 MIMEDIR//EN\r
  BEGIN:VEVENT\r
  UID:0123\r
  DTSTAMP:20130601T080000Z\r
  SUMMARY;LANGUAGE=en-us:Team Meeting\r
  DTSTART:20130610T120000Z\r
  DURATION:PT1H\r
  RRULE:FREQ=WEEKLY;INTERVAL=2\r
  END:VEVENT\r
END:VCALENDAR\r\n")
(.first (biweekly.Biweekly/parse t))
mangstadt commented 7 years ago

biweekly essentially ignores all input until it encounters a valid "BEGIN:VCALENDAR" line. My reasoning for this was to make the parser more flexible. If iCalendar data happens to be nested within other data, the parser can still find it.

Just an executive decision on my part. Not sure if it's useful. Maybe throwing an error would be better.

jjl commented 7 years ago

Well, there is a valid BEGIN:VCALENDAR line, it's just the rest of the entry isn't valid.

I can see the rationale for skipping as described, that could be useful in some circumstances. In this one, however, I'd like to get some errors instead.

Not sure what it'd do to the API to add it as an additional mode, the explosion of static parsing methods in Biweekly is already starting to look a bit silly.... :/

mangstadt commented 7 years ago

Well, there is a valid BEGIN:VCALENDAR line, it's just the rest of the entry isn't valid.

No, there's not. If a line begins with whitespace, then the parser treats it as a "folded" line (a continuation of the previous line). So, when the parser unfolds the lines, the input turns into this:

BEGIN:VCALENDAR VERSION:2.0 PRODID:-//Microsoft Corporation//...
END:VCALENDAR