diff --git a/app/helpers/common_helper.rb b/app/helpers/common_helper.rb
index 8a1efe427..9946e9c55 100644
--- a/app/helpers/common_helper.rb
+++ b/app/helpers/common_helper.rb
@@ -1,6 +1,6 @@
module CommonHelper
def render_google_analytics_code
- if Rails.env == "production" && SiteSetting.ga_tracking_code.present?
+ if Rails.env == "production" && SiteSetting.ga_tracking_code.present?
render partial: "common/google_analytics"
end
end
diff --git a/app/helpers/composer_messages_helper.rb b/app/helpers/composer_messages_helper.rb
deleted file mode 100644
index dd95c7517..000000000
--- a/app/helpers/composer_messages_helper.rb
+++ /dev/null
@@ -1,2 +0,0 @@
-module ComposerMessagesHelper
-end
diff --git a/app/jobs/regular/pull_hotlinked_images.rb b/app/jobs/regular/pull_hotlinked_images.rb
index 90f9b4471..4c06be58c 100644
--- a/app/jobs/regular/pull_hotlinked_images.rb
+++ b/app/jobs/regular/pull_hotlinked_images.rb
@@ -1,6 +1,9 @@
+require_dependency 'url_helper'
+
module Jobs
class PullHotlinkedImages < Jobs::Base
+ include UrlHelper
def initialize
# maximum size of the file in bytes
@@ -40,11 +43,13 @@ module Jobs
if downloaded_urls[src].present?
url = downloaded_urls[src]
escaped_src = src.gsub("?", "\\?").gsub(".", "\\.").gsub("+", "\\+")
- # there are 5 ways to insert an image in a post
+ # there are 6 ways to insert an image in a post
# HTML tag -
raw.gsub!(/src=["']#{escaped_src}["']/i, "src='#{url}'")
# BBCode tag - [img]http://...[/img]
raw.gsub!(/\[img\]#{escaped_src}\[\/img\]/i, "[img]#{url}[/img]")
+ # Markdown linked image - [](http://...)
+ raw.gsub!(/\[!\[([^\]]*)\]\(#{escaped_src}\)\]/) { "[
]" }
# Markdown inline - 
raw.gsub!(/!\[([^\]]*)\]\(#{escaped_src}\)/) { "" }
# Markdown reference - [x]: http://
diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rb
index f1e8558a2..794c5eb60 100644
--- a/lib/cooked_post_processor.rb
+++ b/lib/cooked_post_processor.rb
@@ -2,9 +2,11 @@
# For example, inserting the onebox content, or image sizes/thumbnails.
require_dependency "oneboxer"
+require_dependency 'url_helper'
class CookedPostProcessor
include ActionView::Helpers::NumberHelper
+ include UrlHelper
def initialize(post, opts={})
@dirty = false
@@ -124,10 +126,11 @@ class CookedPostProcessor
def is_a_hyperlink?(img)
parent = img.parent
while parent
- return if parent.name == "a"
+ return true if parent.name == "a"
break unless parent.respond_to? :parent
parent = parent.parent
end
+ false
end
def add_lightbox!(img, original_width, original_height, upload=nil)
@@ -206,17 +209,6 @@ class CookedPostProcessor
end
end
- def is_local(url)
- Discourse.store.has_been_uploaded?(url) || url =~ /^\/assets\//
- end
-
- def absolute(url)
- url =~ /^\/[^\/]/ ? (Discourse.asset_host || Discourse.base_url_no_prefix) + url : url
- end
-
- def schemaless(url)
- url.gsub(/^https?:/, "")
- end
def pull_hotlinked_images
# is the job enabled?
diff --git a/lib/url_helper.rb b/lib/url_helper.rb
new file mode 100644
index 000000000..8e46e00ee
--- /dev/null
+++ b/lib/url_helper.rb
@@ -0,0 +1,15 @@
+module UrlHelper
+
+ def is_local(url)
+ Discourse.store.has_been_uploaded?(url) || url =~ /^\/assets\//
+ end
+
+ def absolute(url)
+ url =~ /^\/[^\/]/ ? (Discourse.asset_host || Discourse.base_url_no_prefix) + url : url
+ end
+
+ def schemaless(url)
+ url.gsub(/^https?:/, "")
+ end
+
+end
diff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rb
index 3847dadfb..c5453ab42 100644
--- a/spec/components/cooked_post_processor_spec.rb
+++ b/spec/components/cooked_post_processor_spec.rb
@@ -340,4 +340,22 @@ describe CookedPostProcessor do
end
+ context ".is_a_hyperlink?" do
+
+ let(:post) { build(:post) }
+ let(:cpp) { CookedPostProcessor.new(post) }
+ let(:doc) { Nokogiri::HTML::fragment('