Permalink
Browse files

Add scheme to url if it's schemeless

  • Loading branch information...
1 parent 6fb205e commit 1059f56379927ca23b53c7552ff7b8e863799616 Ricardo Panaggio committed Nov 21, 2011
Showing with 2 additions and 0 deletions.
  1. +2 −0 app/helpers/application_helper.rb
@@ -323,6 +323,8 @@ def shorten_url(url, options = {})
# characters, plus the 3-character '...' divider
options = {:length => 63}.merge(options)
half_length = (options[:length] - 3) / 2
+ scheme, _ = URI.split(url)
+ url = "http://#{url}" unless scheme
uri = URI.parse(url)
port = lambda { |uri| [80, 443].include?(uri.port) ? '' : ":#{uri.port}" }
relevant_path = lambda do |uri|

0 comments on commit 1059f56

Please sign in to comment.