From 155cad8b852135704b50ed80cf2ea71964a2cd98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Fri, 5 Jul 2019 20:34:11 +0200 Subject: [PATCH] FIX: only add image size when with & height are in pixels --- app/services/inline_uploads.rb | 6 +++--- spec/services/inline_uploads_spec.rb | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/services/inline_uploads.rb b/app/services/inline_uploads.rb index 31a3319a48d..e5652dbdfc6 100644 --- a/app/services/inline_uploads.rb +++ b/app/services/inline_uploads.rb @@ -220,10 +220,10 @@ class InlineUploads if src && (matched_uploads(src).present? || external_src) text = node.attributes["alt"]&.value - width = node.attributes["width"]&.value - height = node.attributes["height"]&.value + width = node.attributes["width"]&.value.to_i + height = node.attributes["height"]&.value.to_i title = node.attributes["title"]&.value - text = "#{text}|#{width}x#{height}" if width && height + text = "#{text}|#{width}x#{height}" if width > 0 && height > 0 after_html_tag = match[0].present? spaces_before = diff --git a/spec/services/inline_uploads_spec.rb b/spec/services/inline_uploads_spec.rb index 434bf429b42..88e3f39681f 100644 --- a/spec/services/inline_uploads_spec.rb +++ b/spec/services/inline_uploads_spec.rb @@ -267,6 +267,7 @@ RSpec.describe InlineUploads do #{Discourse.base_url}#{upload3.url} #{Discourse.base_url}#{upload3.url} + MD expect(InlineUploads.process(md)).to eq(<<~MD) @@ -283,6 +284,7 @@ RSpec.describe InlineUploads do #{Discourse.base_url}#{upload3.short_path} #{Discourse.base_url}#{upload3.short_path} ![|5x4](#{upload.short_url}) + ![](#{upload.short_url}) MD end