From 307d7796b10801d90742a0ae3cf0ba8a5134c8c4 Mon Sep 17 00:00:00 2001 From: Fire Demon Date: Sun, 16 Aug 2020 04:40:29 -0500 Subject: [Command Tags] Handle escaping command sigil in arguments --- app/lib/command_tag/processor.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'app/lib') diff --git a/app/lib/command_tag/processor.rb b/app/lib/command_tag/processor.rb index 7532d6d85..8e540e148 100644 --- a/app/lib/command_tag/processor.rb +++ b/app/lib/command_tag/processor.rb @@ -20,6 +20,7 @@ class CommandTag::Processor MENTIONS_OR_HASHTAGS_RE = /(?:(?:#{Account::MENTION_RE}|#{Tag::HASHTAG_RE})\s*)+/.freeze PARSEABLE_RE = /^\s*(?:#{MENTIONS_OR_HASHTAGS_RE})?#!|%%.+?%%/.freeze STATEMENT_RE = /^\s*#!\s*[^\n]+ (?:start|begin|do)$.*?\n\s*#!\s*(?:end|stop|done)\s*$|^\s*#!\s*.*?\s*$/im.freeze + STATEMENT_PARSE_RE = /'([^']*)'|"([^"]*)"|(\S+)|\s+(?:start|begin|do)\s*$\n+(.*)\n\s*#!\s*(?:end|stop|done)\s*\z/im.freeze TEMPLATE_RE = /%%\s*(\S+.*?)\s*%%/.freeze ESCAPE_MAP = { '\n' => "\n", @@ -148,7 +149,7 @@ class CommandTag::Processor statement = unescape_literals(Regexp.last_match(0).strip[2..-1]) next if statement.blank? - statement_array = statement.scan(/'([^']*)'|"([^"]*)"|(\S+)|\s+(?:start|begin|do)\s*$\n+(.*)\n\s*#!\s*(?:end|stop|done)\s*\z/im).flatten.compact + statement_array = statement.scan(STATEMENT_PARSE_RE).flatten.compact.map { |arg| arg.gsub('\#!', '#!') } statement_array[0] = statement_array[0].strip.tr(':.\- ', '_').gsub(/__+/, '_').downcase next unless statement_array[0].match?(/\A[\w_]+\z/) -- cgit