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)
|
escaped_src = Regexp.escape(original_src)
|
||||||
|
|
||||||
replace_raw = ->(match, match_src, replacement, _index) {
|
replace_raw = ->(match, match_src, replacement, _index) {
|
||||||
if src.include?(match_src)
|
if remove_scheme(src) == remove_scheme(match_src)
|
||||||
|
|
||||||
replacement =
|
replacement =
|
||||||
if replacement.include?(InlineUploads::PLACEHOLDER)
|
if replacement.include?(InlineUploads::PLACEHOLDER)
|
||||||
|
|
|
@ -83,6 +83,17 @@ describe Jobs::PullHotlinkedImages do
|
||||||
RAW
|
RAW
|
||||||
end
|
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
|
it 'replaces images without protocol' do
|
||||||
url = image_url.sub(/^https?\:/, '')
|
url = image_url.sub(/^https?\:/, '')
|
||||||
post = Fabricate(:post, raw: "<img alt='test' src='#{url}'>")
|
post = Fabricate(:post, raw: "<img alt='test' src='#{url}'>")
|
||||||
|
|
Loading…
Reference in New Issue