Commit 4b10592b authored by Robert Speicher's avatar Robert Speicher

Merge branch 'issue_58494' into 'master'

Prevent rewritting plain links as embedded

Closes #58494

See merge request gitlab-org/gitlab-ce!31489
parents 37dd2aea 831ceea9
---
title: Prevent turning plain links into embedded when moving issues
merge_request: 31489
author:
type: fixed
......@@ -27,7 +27,15 @@ module Gitlab
klass = target_parent.is_a?(Namespace) ? NamespaceFileUploader : FileUploader
moved = klass.copy_to(file, target_parent)
moved.markdown_link
moved_markdown = moved.markdown_link
# Prevents rewrite of plain links as embedded
if was_embedded?(markdown)
moved_markdown
else
moved_markdown.sub(/\A!/, "")
end
end
end
......@@ -43,6 +51,10 @@ module Gitlab
referenced_files.compact.select(&:exists?)
end
def was_embedded?(markdown)
markdown.starts_with?("!")
end
private
def find_file(project, secret, file)
......
......@@ -55,6 +55,17 @@ describe Gitlab::Gfm::UploadsRewriter do
end
end
it 'does not rewrite plain links as embedded' do
embedded_link = image_uploader.markdown_link
plain_image_link = embedded_link.sub(/\A!/, "")
text = "#{plain_image_link} and #{embedded_link}"
moved_text = described_class.new(text, old_project, user).rewrite(new_project)
expect(moved_text.scan(/!\[.*?\]/).count).to eq(1)
expect(moved_text.scan(/\A\[.*?\]/).count).to eq(1)
end
context "file are stored locally" do
include_examples "files are accessible"
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