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:
commit
4b10592b81
3 changed files with 29 additions and 1 deletions
5
changelogs/unreleased/issue_58494.yml
Normal file
5
changelogs/unreleased/issue_58494.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue