From 64d5d1bec6ff18591ef4b105394a18cde087b53f Mon Sep 17 00:00:00 2001 From: Fire Demon Date: Mon, 27 Jul 2020 13:04:14 -0500 Subject: [Bug, Command Tags] Consider body blank if left with only mentions and hashtags to prevent accidental mentions --- app/lib/command_tag/processor.rb | 6 +++--- 1 file 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) -- cgit