From 806f0ca19d0e0f0f3e2e25a097a484710e034294 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Wed, 20 Jun 2018 10:47:14 +0800 Subject: [PATCH] FIX: URL with params for svg images should not be light boxed. --- lib/cooked_post_processor.rb | 9 ++++++++- spec/components/cooked_post_processor_spec.rb | 13 +++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rb index 93866749e54..e89cee74bb2 100644 --- a/lib/cooked_post_processor.rb +++ b/lib/cooked_post_processor.rb @@ -541,7 +541,14 @@ class CookedPostProcessor private def is_svg?(img) - File.extname(img["src"]) == '.svg' + path = + begin + URI(img["src"]).path + rescue URI::InvalidURIError, URI::InvalidComponentError + nil + end + + File.extname(path) == '.svg' if path end end diff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rb index 1c3da190cca..0d1fa216a31 100644 --- a/spec/components/cooked_post_processor_spec.rb +++ b/spec/components/cooked_post_processor_spec.rb @@ -178,6 +178,19 @@ describe CookedPostProcessor do expect(cpp.html).to match_html("

") end + + describe 'when image src is an URL' do + let(:post) do + Fabricate(:post, raw: '') + end + + it 'should not add lightbox' do + SiteSetting.crawl_images = true + cpp.post_process_images + + expect(cpp.html).to match_html("

") + end + end end end