From dc6b13e4d205fd148d10d56d1f38f0b12d55825d Mon Sep 17 00:00:00 2001 From: Vinoth Kannan Date: Wed, 17 Jul 2019 11:13:50 +0530 Subject: [PATCH] FIX: when 'raw' started with non-image upload url it's not converted to short-url. dd0f0494c64e75046a4f26e3e46c132edb750cb0 --- app/services/inline_uploads.rb | 8 +++++--- spec/services/inline_uploads_spec.rb | 7 ++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/services/inline_uploads.rb b/app/services/inline_uploads.rb index 6f1cedeb4a4..0473b1c81c1 100644 --- a/app/services/inline_uploads.rb +++ b/app/services/inline_uploads.rb @@ -74,11 +74,13 @@ class InlineUploads markdown.scan(/(\n{2,}|\A)#{regexp}$/) do |match| if match[1].present? extension = match[1].split(".")[-1].downcase - next if FileHelper.supported_images.exclude?(extension) - index = $~.offset(2)[0] indexes << index - raw_matches << [match[1], match[1], +"![](#{PLACEHOLDER})", index] + if FileHelper.supported_images.include?(extension) + raw_matches << [match[1], match[1], +"![](#{PLACEHOLDER})", index] + else + raw_matches << [match[1], match[1], ++"#{Discourse.base_url}#{PATH_PLACEHOLDER}", index] + end end end diff --git a/spec/services/inline_uploads_spec.rb b/spec/services/inline_uploads_spec.rb index dd9c1090597..79f6e78d794 100644 --- a/spec/services/inline_uploads_spec.rb +++ b/spec/services/inline_uploads_spec.rb @@ -231,13 +231,18 @@ RSpec.describe InlineUploads do it "should correct non image URLs to the short url" do SiteSetting.authorized_extensions = "mp4" upload = Fabricate(:video_upload) + upload2 = Fabricate(:video_upload) md = <<~MD - #{GlobalSetting.cdn_url}#{upload.url} + #{Discourse.base_url}#{upload.url} + + #{Discourse.base_url}#{upload.url} #{Discourse.base_url}#{upload2.url} MD expect(InlineUploads.process(md)).to eq(<<~MD) #{Discourse.base_url}#{upload.short_path} + + #{Discourse.base_url}#{upload.short_path} #{Discourse.base_url}#{upload2.short_path} MD end