about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFire Demon <firedemon@creature.cafe>2020-08-16 04:40:29 -0500
committerFire Demon <firedemon@creature.cafe>2020-08-30 05:45:18 -0500
commit307d7796b10801d90742a0ae3cf0ba8a5134c8c4 (patch)
tree62a06a9e5b55ef9e75885723f04fadf9e69c14a7
parent49535c6a1a6dc63daa1158dddac6155e999a4919 (diff)
[Command Tags] Handle escaping command sigil in arguments
-rw-r--r--app/lib/command_tag/processor.rb3
1 files changed, 2 insertions, 1 deletions
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/)