Commit 8d416b7b authored by Imre Farkas's avatar Imre Farkas

Merge branch '14244-slack-does-not-show-image-from-issue-comments' into 'master'

Fix relative links in Slack message

See merge request gitlab-org/gitlab!22608
parents cd25ff7f 2903cc35
......@@ -4,6 +4,8 @@ require 'slack-notifier'
module ChatMessage
class BaseMessage
RELATIVE_LINK_REGEX = /!\[[^\]]*\]\((\/uploads\/[^\)]*)\)/.freeze
attr_reader :markdown
attr_reader :user_full_name
attr_reader :user_name
......@@ -59,7 +61,11 @@ module ChatMessage
end
def format(string)
Slack::Notifier::LinkFormatter.format(string)
Slack::Notifier::LinkFormatter.format(format_relative_links(string))
end
def format_relative_links(string)
string.gsub(RELATIVE_LINK_REGEX, "#{project_url}\\1")
end
def attachment_color
......
---
title: Fix relative links in Slack message
merge_request: 22608
author:
type: fixed
# frozen_string_literal: true
require 'spec_helper'
describe ChatMessage::BaseMessage do
let(:base_message) { described_class.new(args) }
let(:args) { { project_url: 'https://gitlab-domain.com' } }
describe '#fallback' do
subject { base_message.fallback }
before do
allow(base_message).to receive(:message).and_return(message)
end
context 'without relative links' do
let(:message) { 'Just another *markdown* message' }
it { is_expected.to eq(message) }
end
context 'with relative links' do
let(:message) { 'Check this out ![Screenshot1](/uploads/Screenshot1.png)' }
it { is_expected.to eq('Check this out https://gitlab-domain.com/uploads/Screenshot1.png') }
end
context 'with multiple relative links' do
let(:message) { 'Check this out ![Screenshot1](/uploads/Screenshot1.png). And this ![Screenshot2](/uploads/Screenshot2.png)' }
it { is_expected.to eq('Check this out https://gitlab-domain.com/uploads/Screenshot1.png. And this https://gitlab-domain.com/uploads/Screenshot2.png') }
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment