about summary refs log tree commit diff
path: root/app/lib/command_tag
diff options
context:
space:
mode:
authorFire Demon <firedemon@creature.cafe>2020-07-27 13:04:14 -0500
committerFire Demon <firedemon@creature.cafe>2020-08-30 05:45:16 -0500
commit64d5d1bec6ff18591ef4b105394a18cde087b53f (patch)
tree96d5629a9e7b9aff9fefa6d1a63c1c13918f1729 /app/lib/command_tag
parent2fdc484caa2d6471116a28997bb0b7e04df6870e (diff)
[Bug, Command Tags] Consider body blank if left with only mentions and hashtags to prevent accidental mentions
Diffstat (limited to 'app/lib/command_tag')
-rw-r--r--app/lib/command_tag/processor.rb6
1 files changed, 3 insertions, 3 deletions
diff --git a/app/lib/command_tag/processor.rb b/app/lib/command_tag/processor.rb
index 0ec088e55..4601fee91 100644
--- a/app/lib/command_tag/processor.rb
+++ b/app/lib/command_tag/processor.rb
@@ -17,6 +17,7 @@ class CommandTag::Processor
 
   STATEMENT_RE = /^\s*#!\s*([^\n]+ (?:start|begin|do)$.*?)\n\s*#!\s*(?:end|stop|done)\s*$|^\s*#!\s*(.*?)\s*$/im.freeze
   TEMPLATE_RE = /%%\s*(.*?)\s*%%/.freeze
+  MENTIONS_OR_HASHTAGS_RE = /(?:(?:#{Account::MENTION_RE}|#{Tag::HASHTAG_RE})\s*)+/.freeze
   ESCAPE_MAP = {
     '\n' => "\n",
     '\r' => "\r",
@@ -48,7 +49,7 @@ class CommandTag::Processor
     @text = parse_templates(@text).rstrip
     %w(before_save once_before_save).each { |suffix| execute_statements(suffix) }
 
-    if @text.blank? || @text.gsub(Account::MENTION_RE, '').strip.blank?
+    if @text.blank? || @text.gsub(MENTIONS_OR_HASHTAGS_RE, '').strip.blank?
       %w(when_blank once_when_blank).each { |suffix| execute_statements(suffix) }
 
       unless (@status.published? && !@status.edited.zero?) || @text.present?
@@ -81,8 +82,7 @@ class CommandTag::Processor
   end
 
   def prepare_input(text)
-    text.gsub(/\r\n|\n\r|\r/, "\n")
-        .gsub(/^\s*((?:(?:#{Account::MENTION_RE}|#{Tag::HASHTAG_RE})\s*)+)#!/, "\\1\n#!")
+    text.gsub(/\r\n|\n\r|\r/, "\n").gsub(/^\s*(#{MENTIONS_OR_HASHTAGS_RE})#!/, "\\1\n#!")
   end
 
   def parse_templates(text)