lib/onebox/helpers.rb in onebox-1.7.3 vs lib/onebox/helpers.rb in onebox-1.7.4
- old
+ new
@@ -17,27 +17,26 @@
def self.fetch_response(location, limit = 5, domain = nil, headers = nil)
raise Net::HTTPError.new('HTTP redirect too deep', location) if limit == 0
uri = URI(location)
- if !uri.host
- uri = URI("#{domain}#{location}")
- end
+ uri = URI("#{domain}#{location}") if !uri.host
+
http = Net::HTTP.new(uri.host, uri.port)
http.open_timeout = Onebox.options.connect_timeout
http.read_timeout = Onebox.options.timeout
if uri.is_a?(URI::HTTPS)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
response = http.request_get(uri.request_uri,headers)
- cookie = response.get_fields('set-cookie')
- if (cookie)
- header = {'cookie' => cookie.join("")}
+ if cookie = response.get_fields('set-cookie')
+ header = { 'cookie' => cookie.join }
end
+
header = nil unless header.is_a? Hash
case response
when Net::HTTPSuccess then response
when Net::HTTPRedirection then fetch_response(response['location'], limit - 1, "#{uri.scheme}://#{uri.host}",header)
@@ -61,18 +60,19 @@
def self.truncate(string, length = 50)
string.size > length ? string[0...(string.rindex(" ", length)||length)] + "..." : string
end
def self.title_attr(meta)
- (meta && !blank?(meta[:title])) ? "title='#{CGI.escapeHTML(meta[:title])}'" : ""
+ (meta && !blank?(meta[:title])) ? "title='#{meta[:title]}'" : ""
end
def self.normalize_url_for_output(url)
+ return "" unless url
url = url.dup
# expect properly encoded url, remove any unsafe chars
url.gsub!("'", "'")
url.gsub!('"', """)
- url.gsub!(/[^a-zA-Z0-9%\-`._~:\/?#\[\]@!$&'\(\)*+,;=]/, "")
+ url.gsub!(/[^\w\-`._~:\/?#\[\]@!$&'\(\)*+,;=]/, "")
url
end
end
end