diff --git a/lib/ld-eventsource/impl/event_parser.rb b/lib/ld-eventsource/impl/event_parser.rb index 0f35d15..270142b 100644 --- a/lib/ld-eventsource/impl/event_parser.rb +++ b/lib/ld-eventsource/impl/event_parser.rb @@ -37,12 +37,14 @@ def items event = maybe_create_event reset_buffers gen.yield event if !event.nil? - else - case line - when /^(\w+): ?(.*)$/ - item = process_field($1, $2) - gen.yield item if !item.nil? - end + elsif (colon = line.index(':')) + name = line.slice(0...colon) + + # delete the colon followed by an optional space + line = line.slice(colon...).delete_prefix(':').delete_prefix(" ") + + item = process_field(name, line) + gen.yield item if !item.nil? end end end @@ -62,8 +64,11 @@ def process_field(name, value) when "event" @type = value.to_sym when "data" - @data << "\n" if @have_data - @data << value + if @have_data + @data << "\n" << value + else + @data = value + end @have_data = true when "id" if !value.include?("\x00")