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:
parent
9f528f0ec2
commit
5774107a2d
|
@ -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)
|
||||
|
|
|
@ -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}'>")
|
||||
|
|
Loading…
Reference in New Issue