From 04ae79896c12dd0d7bdd78aa3b1e229c57682e01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Mon, 23 Oct 2017 17:43:53 +0200 Subject: [PATCH] Exit early when the 'img is already inside an 'a' tag --- lib/cooked_post_processor.rb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rb index 86948b10093..278a570464e 100644 --- a/lib/cooked_post_processor.rb +++ b/lib/cooked_post_processor.rb @@ -200,11 +200,10 @@ class CookedPostProcessor def convert_to_link!(img) src = img["src"] - return if src.blank? + return if src.blank? || is_a_hyperlink?(img) width, height = img["width"].to_i, img["height"].to_i - # TODO: even though get_size is cached, a better solution is to store - # both original and "cropped" dimensions on the uploads table + # TODO: store original dimentions in db original_width, original_height = (get_size(src) || [0, 0]).map(&:to_i) # can't reach the image... @@ -215,7 +214,6 @@ class CookedPostProcessor return if original_width <= width && original_height <= height return if original_width <= SiteSetting.max_image_width && original_height <= SiteSetting.max_image_height - return if is_a_hyperlink?(img) crop = false if original_width.to_f / original_height.to_f < MIN_RATIO_TO_CROP @@ -236,8 +234,7 @@ class CookedPostProcessor parent = img.parent while parent return true if parent.name == "a" - break unless parent.respond_to? :parent - parent = parent.parent + parent = parent.parent if parent.respond_to?(:parent) end false end