Skip to content

Commit 6a50aad

Browse files
committed
support for parsing rrules from ical that are very long and wrap
1 parent ee3171d commit 6a50aad

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

lib/ice_cube/parsers/ical_parser.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,18 @@ module IceCube
22
class IcalParser
33
def self.schedule_from_ical(ical_string, options = {})
44
data = {}
5+
6+
# First join lines that are wrapped
7+
lines = []
58
ical_string.each_line do |line|
9+
if lines[-1] && line =~ /\A[ \t].+\z/
10+
lines[-1] = lines[-1].strip + line.sub(/\A[ \t]+/, "")
11+
else
12+
lines << line
13+
end
14+
end
15+
16+
lines.each do |line|
617
(property, value) = line.split(":")
718
(property, _tzid) = property.split(";")
819
case property

spec/examples/from_ical_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,5 +448,13 @@ def sorted_ical(ical)
448448
it_behaves_like "an invalid ical string"
449449
end
450450
end
451+
452+
describe "ical data with wrapping" do
453+
it "matches simple daily" do
454+
ical_string = "DTSTART:20130314T201500Z\nDTEND:20130314T201545Z\nRRULE:FREQ=WEEKLY;BYDAY=TH;UNT\n IL=20130531T100000Z"
455+
schedule = IceCube::Schedule.from_ical(ical_string)
456+
expect(schedule.to_ical.split(/\n/).select {|x| x =~ /RRULE/}.first).to eq("RRULE:FREQ=WEEKLY;UNTIL=20130531T100000Z;BYDAY=TH")
457+
end
458+
end
451459
end
452460
end

0 commit comments

Comments
 (0)