From 109c10c8836b0f7c52945e1f0577e454c6918da8 Mon Sep 17 00:00:00 2001 From: Claus Strasburger Date: Wed, 9 Oct 2013 20:43:59 +0200 Subject: [PATCH] YoutubeOnebox: FIX HTTP-specific URLs by replacing with protocol-agnostic URLs. This fixes the mixed-content warning for secure instances of discourse, at least for Youtube --- lib/oneboxer/base_onebox.rb | 5 +++++ lib/oneboxer/youtube_onebox.rb | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/lib/oneboxer/base_onebox.rb b/lib/oneboxer/base_onebox.rb index b8187330075..c855bc21dcb 100644 --- a/lib/oneboxer/base_onebox.rb +++ b/lib/oneboxer/base_onebox.rb @@ -32,6 +32,11 @@ module Oneboxer URI.escape(val, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")) end + # Replace any occurence of a HTTP or HTTPS URL in the string with the protocol-agnostic variant + def replace_agnostic(var) + var.gsub! /https?:\/\//, '//' if var.is_a? String + end + end def initialize(url, opts={}) diff --git a/lib/oneboxer/youtube_onebox.rb b/lib/oneboxer/youtube_onebox.rb index 50e0cf8234d..6438b2f3730 100644 --- a/lib/oneboxer/youtube_onebox.rb +++ b/lib/oneboxer/youtube_onebox.rb @@ -6,5 +6,10 @@ module Oneboxer def oembed_endpoint "http://www.youtube.com/oembed?url=#{BaseOnebox.uriencode(@url.sub('https://', 'http://'))}&format=json" end + + def onebox + # Youtube allows HTTP and HTTPS, so replace them with the protocol-agnostic variant + super.each { |entry| BaseOnebox.replace_agnostic entry } + end end end