From 41abebcbcea12219c6a28d1bd0621b37ed9232c4 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Fri, 14 Jun 2019 12:48:31 +0800 Subject: [PATCH] DEV: Support both `http` and `https` for `InlineUploads`. --- app/services/inline_uploads.rb | 8 +++++--- spec/services/inline_uploads_spec.rb | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/services/inline_uploads.rb b/app/services/inline_uploads.rb index 7d80fb8e84f..772fe9ce716 100644 --- a/app/services/inline_uploads.rb +++ b/app/services/inline_uploads.rb @@ -241,10 +241,12 @@ class InlineUploads def self.matched_uploads(node) matches = [] + base_url = Discourse.base_url.sub(/https?:\/\//, "(https?://)") + regexps = [ /(upload:\/\/([a-zA-Z0-9]+)[a-zA-Z0-9\.]*)/, /(\/uploads\/short-url\/([a-zA-Z0-9]+)[a-zA-Z0-9\.]*)/, - /(#{Discourse.base_url}\/uploads\/short-url\/([a-zA-Z0-9]+)[a-zA-Z0-9\.]*)/, + /(#{base_url}\/uploads\/short-url\/([a-zA-Z0-9]+)[a-zA-Z0-9\.]*)/, ] db = RailsMultisite::ConnectionManagement.current_db @@ -257,11 +259,11 @@ class InlineUploads regexps << /((https?:)?#{SiteSetting.Upload.s3_base_url}#{UPLOAD_REGEXP_PATTERN})/ regexps << /(#{SiteSetting.Upload.s3_cdn_url}#{UPLOAD_REGEXP_PATTERN})/ regexps << /(\/uploads\/#{db}#{UPLOAD_REGEXP_PATTERN})/ - regexps << /(#{Discourse.base_url}\/uploads\/#{db}#{UPLOAD_REGEXP_PATTERN})/ + regexps << /(#{base_url}\/uploads\/#{db}#{UPLOAD_REGEXP_PATTERN})/ end else regexps << /(\/uploads\/#{db}#{UPLOAD_REGEXP_PATTERN})/ - regexps << /(#{Discourse.base_url}\/uploads\/#{db}#{UPLOAD_REGEXP_PATTERN})/ + regexps << /(#{base_url}\/uploads\/#{db}#{UPLOAD_REGEXP_PATTERN})/ end node = node.to_s diff --git a/spec/services/inline_uploads_spec.rb b/spec/services/inline_uploads_spec.rb index 13e8c53e8bf..a89d8a2c787 100644 --- a/spec/services/inline_uploads_spec.rb +++ b/spec/services/inline_uploads_spec.rb @@ -190,7 +190,7 @@ RSpec.describe InlineUploads do [1]: #{Discourse.base_url}#{upload.url} - [2]: #{Discourse.base_url}#{upload2.url} + [2]: #{Discourse.base_url.sub("http://", "https://")}#{upload2.url} MD expect(InlineUploads.process(md)).to eq(<<~MD)