Skip to content

Commit

Permalink
Force https for img tag embeds.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefansundin committed Jan 14, 2017
1 parent 2450215 commit 417eef1
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion config/initializers/05-string.rb
Expand Up @@ -54,6 +54,10 @@ def normalize_url
URI::HTTP.new(uri.scheme.downcase, uri.userinfo, uri.host.downcase, port, uri.registry, path, uri.opaque, uri.query, uri.fragment).to_s
end

def https
self.gsub(/^http:/, "https:")
end

def short_host
uri = URI.parse(self)
if uri.host[0..3] == "www."
Expand Down Expand Up @@ -229,7 +233,7 @@ def embed_html(request=nil)
elsif %r{^https?://(?:www\.)?giphy\.com/gifs/(?:.*-)?(?<id>[0-9a-zA-Z]+)(/|\?|&|#|$)} =~ self
"<img src='https://i.giphy.com/#{id}.gif'>"
elsif %r{^https?://[a-z0-9\-._~:/?#\[\]@!$&'()*+,;=]+\.(?:gif|jpg|png)(?::large)?}i =~ self
"<img src='#{self}'>"
"<img src='#{self.https}'>"
elsif %r{^https?://[a-z0-9\-._~:/?#\[\]@!$&'()*+,;=]+\.mp4}i =~ self
query = CGI.parse(URI.parse(self).query)
width = query["w"][0] || "640"
Expand Down

0 comments on commit 417eef1

Please sign in to comment.