From 87a905b01dab90acd2e62975ac180e14b41f3eb8 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Sat, 7 Mar 2009 14:02:55 +0100 Subject: messagemapper: fix regexp creation for double-optional templates When a mapping template had a double optional key such as 'something [[double] optional]' the resuting regexp moved the spacing between the (converted) double brackets, requiring extra spacing before the 'optional' keyword. Fix by moving spacing inside all consecutive brackets before converting brackets into their regexp form. --- lib/rbot/messagemapper.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/rbot/messagemapper.rb b/lib/rbot/messagemapper.rb index 9501ac59..1162a3a2 100644 --- a/lib/rbot/messagemapper.rb +++ b/lib/rbot/messagemapper.rb @@ -514,7 +514,9 @@ class Bot s = "#{not_needed ? "(?:" : ""}#{whites}(#{sub})#{ not_needed ? ")?" : ""}" } # debug "Replaced dyns: #{rx.inspect}" - rx.gsub!(/((?:\\ )*)\\\[/, "(?:\\1") + rx.gsub!(/((?:\\ )*)((?:\\\[)+)/, '\2\1') + # debug "Corrected optionals spacing: #{rx.inspect}" + rx.gsub!(/\\\[/, "(?:") rx.gsub!(/\\\]/, ")?") # debug "Delimited optionals: #{rx.inspect}" rx.gsub!(/(?:\\ )+/, "\\s+") -- cgit v1.2.3