Use `gsub` instead of `gsub!` to not modify frozen literals

This commit is contained in:
Andreas Nedbal 2022-01-16 22:13:41 +01:00 committed by Andreas Nedbal
parent 3bdca34c2d
commit c84b6a61bd
2 changed files with 7 additions and 6 deletions

View File

@ -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)

View File

@ -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