Skip to content

Commit

Permalink
Fix regex memory usage error
Browse files Browse the repository at this point in the history
  • Loading branch information
sw-square committed Jun 13, 2022
1 parent 68a3a91 commit 8b93b58
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions lib/ld-eventsource/impl/event_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down

0 comments on commit 8b93b58

Please sign in to comment.