FIX: allows to parse event option with spaces in value

FIX: allows to parse event option with spaces in value

diff --git a/lib/discourse_post_event/event_parser.rb b/lib/discourse_post_event/event_parser.rb
index 354cec7..c245a4d 100644
--- a/lib/discourse_post_event/event_parser.rb
+++ b/lib/discourse_post_event/event_parser.rb
@@ -1,6 +1,7 @@
 # frozen_string_literal: true
 
-EVENT_REGEX = /\[wrap=event\s(.*?)\](?:\n|\\n)?\[\/wrap\]/m
+EVENT_REGEX = /\[wrap=event\s(.*?)\]/m
+EVENT_OPTIONS_REGEX = /(\w+\=".*?")/m
 
 VALID_OPTIONS = [
   :start,
@@ -20,8 +21,8 @@ module DiscoursePostEvent
 
     def self.extract_options(str)
       options = nil
-      str.split(" ").each do |option|
-        key, value = option.split("=")
+      str.scan(EVENT_OPTIONS_REGEX).each do |option|
+        key, value = option[0].split("=")
         if VALID_OPTIONS.include?(key.to_sym) && value
           options ||= {}
           options[key.to_sym] = value.delete('\\"')
diff --git a/spec/lib/event_parser_spec.rb b/spec/lib/event_parser_spec.rb
index e7368a8..109314e 100644
--- a/spec/lib/event_parser_spec.rb
+++ b/spec/lib/event_parser_spec.rb
@@ -32,6 +32,11 @@ describe DiscoursePostEvent::EventParser do
     expect(events[1][:start]).to eq("foo")
   end
 
+  it 'parses options where value has spaces' do
+    events = subject.extract_events('[wrap=event start="foo" name="bar baz"]\n[/wrap]')
+    expect(events[0][:name]).to eq("bar baz")
+  end
+
   it 'doesn’t parse invalid options' do
     events = subject.extract_events("I am going to get that fixed.\n\n[wrap=event start=\"foo\" something=\"bar\"]\n[/wrap]")
     expect(events[0][:something]).to be(nil)

GitHub sha: 04c4052f