From c84b6a61bd26835528f5d4c7f4ee3939ee363e3d Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Sun, 16 Jan 2022 22:13:41 +0100 Subject: [PATCH] Use `gsub` instead of `gsub!` to not modify frozen literals --- app/services/flavored_markdown.rb | 5 +++-- app/services/twittered_markdown.rb | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/services/flavored_markdown.rb b/app/services/flavored_markdown.rb index 0110954f..781438c9 100644 --- a/app/services/flavored_markdown.rb +++ b/app/services/flavored_markdown.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class FlavoredMarkdown < Redcarpet::Render::HTML include Rails.application.routes.url_helpers include SharedMarkers @@ -7,10 +9,9 @@ class FlavoredMarkdown < Redcarpet::Render::HTML end def wrap_mentions(text) - text.gsub! /(^|\s)(@[a-zA-Z0-9_]{1,16})/ do + text.gsub(/(^|\s)(@[a-zA-Z0-9_]{1,16})/) do "#{$1}[#{$2}](#{show_user_profile_path $2.tr('@', '')})" end - text end def header(text, _header_level) diff --git a/app/services/twittered_markdown.rb b/app/services/twittered_markdown.rb index aeadf428..8787c1b4 100644 --- a/app/services/twittered_markdown.rb +++ b/app/services/twittered_markdown.rb @@ -1,12 +1,13 @@ -class TwitteredMarkdown < Redcarpet::Render::StripDown +# frozen_string_literal: true +class TwitteredMarkdown < Redcarpet::Render::StripDown def preprocess(text) wrap_mentions(text) end def wrap_mentions(text) - text.gsub! /(^|\s)@([a-zA-Z0-9_]{1,16})/ do - local_user = User.find_by_screen_name($2) + text.gsub(/(^|\s)@([a-zA-Z0-9_]{1,16})/) do + local_user = User.find_by(screen_name: $2) if local_user.nil? "#{$1}#{$2}" else @@ -18,6 +19,5 @@ class TwitteredMarkdown < Redcarpet::Render::StripDown end end end - text end end