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 May 25, 2022
1 parent 68a3a91 commit f0091ec
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 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,16 @@ 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)
next unless name.match?(/^\w+$/)

# delete the colon followed by an optional space
line.delete_prefix!(':')
line.delete_prefix!(' ')

item = process_field(name, line)
gen.yield item if !item.nil?
end
end
end
Expand All @@ -62,8 +66,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 f0091ec

Please sign in to comment.