Skip to content
Snippets Groups Projects
Verified Commit 823a57dd authored by Anush Kumar's avatar Anush Kumar Committed by GitLab
Browse files

Handled Multiline Regex

parent 20b82b09
No related branches found
No related tags found
1 merge request!180946Resolve "Update Import::UsernameMentionRewriter regex to catch newline and spaces."
......@@ -25,22 +25,29 @@ def update_username_mentions(relation_hash)
def wrap_mentions_in_backticks(text)
return text unless text.present?
if MENTION_REGEX.match?(text)
text = MENTION_REGEX.replace_gsub(text) do |match|
case match[0]
when /^`/
match[0]
when /^ /
" `#{match[0].lstrip}`"
when /^\(/
"(`#{match[0].sub(/^./, '')}`"
else
"`#{match[0]}`"
resultant_array = []
split_array = text.split("\n")
split_array.each do |line|
if MENTION_REGEX.match?(line)
line = MENTION_REGEX.replace_gsub(line) do |match|
case match[0]
when /^`/
match[0]
when /^ /
" `#{match[0].lstrip}`"
when /^\(/
"(`#{match[0].sub(/^./, '')}`"
else
"`#{match[0]}`"
end
end
end
resultant_array << line
end
text
resultant_array.join("\n")
end
end
end
......
......@@ -93,4 +93,13 @@
end
end
end
context 'when the text contains username in the new line' do
let(:original_text) { "Hello,\n@username is mentioned here.\nThis is the next line." }
let(:expected_text) { "Hello,\n`@username` is mentioned here.\nThis is the next line." }
it 'wraps the username in backticks and it should be properly formatted in the new line' do
expect(instance.wrap_mentions_in_backticks(original_text)).to eq(expected_text)
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment