Prevent rewritting plain links as embedded
Prevents rewritting plain image/video links as embedded when moving issues.
This commit is contained in:
parent
b82931359b
commit
831ceea924
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
|
klass = target_parent.is_a?(Namespace) ? NamespaceFileUploader : FileUploader
|
||||||
moved = klass.copy_to(file, target_parent)
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -43,6 +51,10 @@ module Gitlab
|
||||||
referenced_files.compact.select(&:exists?)
|
referenced_files.compact.select(&:exists?)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def was_embedded?(markdown)
|
||||||
|
markdown.starts_with?("!")
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def find_file(project, secret, file)
|
def find_file(project, secret, file)
|
||||||
|
|
|
@ -55,6 +55,17 @@ describe Gitlab::Gfm::UploadsRewriter do
|
||||||
end
|
end
|
||||||
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
|
context "file are stored locally" do
|
||||||
include_examples "files are accessible"
|
include_examples "files are accessible"
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue