Merge branch 'issue_58494' into 'master'

Prevent rewritting plain links as embedded

Closes #58494

See merge request gitlab-org/gitlab-ce!31489
This commit is contained in:
Robert Speicher 2019-08-09 20:41:12 +00:00
commit 4b10592b81
3 changed files with 29 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
title: Prevent turning plain links into embedded when moving issues
merge_request: 31489
author:
type: fixed

View file

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

View 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