From ee40a95e58db4c5ee6171c7fc2b2ffd0a0c707e9 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 7 Aug 2014 12:58:26 -0400 Subject: [PATCH] FIX: Don't return protocol relative URLs for open graph images - we can't be sure our site supports what protocol a remote site is requesting. --- app/helpers/application_helper.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 16401e1f296..06496381339 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -85,10 +85,17 @@ module ApplicationHelper opts[:image] ||= "#{Discourse.base_url}#{SiteSetting.logo_small_url}" opts[:url] ||= "#{Discourse.base_url}#{request.fullpath}" + # Use the correct scheme for open graph + if opts[:image].present? && opts[:image].start_with?("//") + uri = URI(Discourse.base_url) + opts[:image] = "#{uri.scheme}:#{opts[:image]}" + end + # Add opengraph tags result = tag(:meta, property: 'og:site_name', content: SiteSetting.title) << "\n" result << tag(:meta, name: 'twitter:card', content: "summary") + [:image, :url, :title, :description, 'image:width', 'image:height'].each do |property| if opts[property].present? escape = (property != :image)