FIX: downloaded image URLs incorrectly replaced in post raw. (#9014)

Previously, while replacing the downloaded image URL `http://wiki.mozilla.org/images/2/2e/Longcat1.png` similar non-image URL `http://wiki.mozilla.org/images/2` was replaced wrongly.
This commit is contained in:
Vinoth Kannan 2020-02-27 10:22:55 +05:30 committed by GitHub
parent 9f528f0ec2
commit 5774107a2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -95,7 +95,7 @@ module Jobs
escaped_src = Regexp.escape(original_src)
replace_raw = ->(match, match_src, replacement, _index) {
if src.include?(match_src)
if remove_scheme(src) == remove_scheme(match_src)
replacement =
if replacement.include?(InlineUploads::PLACEHOLDER)

View File

@ -83,6 +83,17 @@ describe Jobs::PullHotlinkedImages do
RAW
end
it 'replaces correct image URL' do
url = image_url.sub("/2e/Longcat1.png", '')
post = Fabricate(:post, raw: "[Images](#{url})\n![](#{image_url})")
expect do
Jobs::PullHotlinkedImages.new.execute(post_id: post.id)
end.to change { Upload.count }.by(1)
expect(post.reload.raw).to eq("[Images](#{url})\n![](#{Upload.last.short_url})")
end
it 'replaces images without protocol' do
url = image_url.sub(/^https?\:/, '')
post = Fabricate(:post, raw: "<img alt='test' src='#{url}'>")