FIX: allows to parse event option with spaces in value
This commit is contained in:
parent
d12d45d247
commit
04c4052f99
|
|
@ -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('\\"')
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue