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
This commit is contained in:
Claus Strasburger 2013-10-09 20:43:59 +02:00
parent c48030f1ef
commit 109c10c883
2 changed files with 10 additions and 0 deletions

View file

@ -32,6 +32,11 @@ module Oneboxer
URI.escape(val, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")) URI.escape(val, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
end 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 end
def initialize(url, opts={}) def initialize(url, opts={})

View file

@ -6,5 +6,10 @@ module Oneboxer
def oembed_endpoint def oembed_endpoint
"http://www.youtube.com/oembed?url=#{BaseOnebox.uriencode(@url.sub('https://', 'http://'))}&format=json" "http://www.youtube.com/oembed?url=#{BaseOnebox.uriencode(@url.sub('https://', 'http://'))}&format=json"
end 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
end end