lib/autolink.rb in twitter-text-1.2.4 vs lib/autolink.rb in twitter-text-1.2.5

- old
+ new

@@ -1,6 +1,5 @@ - module Twitter # A module for including Tweet auto-linking in a class. The primary use of this is for helpers/views so they can auto-link # usernames, lists, hashtags and URLs. module Autolink extend self include ActionView::Helpers::TagHelper #tag_options needed by auto_link @@ -138,17 +137,24 @@ options = href_options.dup options[:rel] = "nofollow" unless options.delete(:suppress_no_follow) text.gsub(Twitter::Regex[:valid_url]) do all, before, url, protocol, domain, path, query_string = $1, $2, $3, $4, $5, $6, $7 - if !protocol.blank? || domain =~ Twitter::Regex[:probable_tld] + if !protocol.blank? # || domain =~ Twitter::Regex[:probable_tld_domain] html_attrs = tag_options(options.stringify_keys) || "" full_url = ((protocol =~ Twitter::Regex[:www] || protocol.blank?) ? "http://#{url}" : url) "#{before}<a href=\"#{html_escape(full_url)}\"#{html_attrs}>#{html_escape(url)}</a>" + elsif all =~ Twitter::Regex[:probable_tld_domain] + before_tld, tld_domain = $1, $2 + + html_attrs = tag_options(options.stringify_keys) || "" + full_url = "http://#{tld_domain}" + prefix = (before_tld == before ? before : "#{before}#{before_tld}") + "#{prefix}<a href=\"#{html_escape(full_url)}\"#{html_attrs}>#{html_escape(tld_domain)}</a>" else all end end end end -end \ No newline at end of file +end