twitter-text 1.2.5 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- twitter-text (1.2.5)
4
+ twitter-text (1.3.0)
5
5
  actionpack
6
6
 
7
7
  GEM
data/README.rdoc CHANGED
@@ -29,7 +29,15 @@ usernames, lists, hashtags and URLs.
29
29
 
30
30
  html = auto_link("link @user, please #request")
31
31
  end
32
-
32
+
33
+ # For Ruby on Rails you want to add this to app/helpers/application_helper.rb
34
+ module ApplicationHelper
35
+ include Twitter::Autolink
36
+ end
37
+
38
+ # Now the auto_link function is available in every view. So in index.html.erb:
39
+ <%= auto_link("link @user, please #request") %>
40
+
33
41
  === Usernames
34
42
 
35
43
  Username extraction and linking matches all valid Twitter usernames but does
@@ -79,6 +87,7 @@ Thanks to everybody who has filed issues, provided feedback or contributed patch
79
87
  * Ben Cherry - http://github.com/bcherry
80
88
  * Patrick Ewing - http://github.com/hoverbird
81
89
  * Jeff Smick - http://github.com/sprsquish
90
+ * Kenneth Kufluk - https://github.com/kennethkufluk
82
91
 
83
92
  * Patches from the community …
84
93
  * Jean-Philippe Bougie - http://github.com/jpbougie
data/lib/autolink.rb CHANGED
@@ -139,17 +139,9 @@ module Twitter
139
139
 
140
140
  text.gsub(Twitter::Regex[:valid_url]) do
141
141
  all, before, url, protocol, domain, path, query_string = $1, $2, $3, $4, $5, $6, $7
142
- if !protocol.blank? # || domain =~ Twitter::Regex[:probable_tld_domain]
142
+ if !protocol.blank?
143
143
  html_attrs = tag_options(options.stringify_keys) || ""
144
- full_url = ((protocol =~ Twitter::Regex[:www] || protocol.blank?) ? "http://#{url}" : url)
145
- "#{before}<a href=\"#{html_escape(full_url)}\"#{html_attrs}>#{html_escape(url)}</a>"
146
- elsif all =~ Twitter::Regex[:probable_tld_domain]
147
- before_tld, tld_domain = $1, $2
148
-
149
- html_attrs = tag_options(options.stringify_keys) || ""
150
- full_url = "http://#{tld_domain}"
151
- prefix = (before_tld == before ? before : "#{before}#{before_tld}")
152
- "#{prefix}<a href=\"#{html_escape(full_url)}\"#{html_attrs}>#{html_escape(tld_domain)}</a>"
144
+ "#{before}<a href=\"#{html_escape(url)}\"#{html_attrs}>#{html_escape(url)}</a>"
153
145
  else
154
146
  all
155
147
  end
data/lib/extractor.rb CHANGED
@@ -127,15 +127,7 @@ module Twitter
127
127
  start_position = valid_url_match_data.char_begin(3)
128
128
  end_position = valid_url_match_data.char_end(3)
129
129
  urls << {
130
- :url => ((protocol =~ Twitter::Regex[:www] || protocol.blank?) ? "http://#{url}" : url),
131
- :indices => [start_position, end_position]
132
- }
133
- elsif all =~ Twitter::Regex[:probable_tld_domain]
134
- tld_domain = $2
135
- start_position = valid_url_match_data.char_begin(1) + $~.char_begin(2)
136
- end_position = valid_url_match_data.char_begin(1) + $~.char_end(2)
137
- urls << {
138
- :url => "http://#{tld_domain}",
130
+ :url => url,
139
131
  :indices => [start_position, end_position]
140
132
  }
141
133
  end
data/lib/regex.rb CHANGED
@@ -56,12 +56,7 @@ module Twitter
56
56
  REGEXEN[:valid_preceding_chars] = /(?:[^-\/"':!=A-Z0-9_@@]|^|\:)/i
57
57
  REGEXEN[:valid_domain] = /(?:[^[:punct:]\s][\.-](?=[^[:punct:]\s])|[^[:punct:]\s]){1,}\.[a-z]{2,}(?::[0-9]+)?/i
58
58
 
59
- # For protocol-less URLs, we'll accept them if they end in one of a handful of likely TLDs
60
- REGEXEN[:probable_tld_domain] = /^(.*?)((?:[a-z0-9_\.\-]+)\.(?:com|net|org|gov|edu))$/i
61
-
62
- REGEXEN[:www] = /www\./i
63
-
64
- REGEXEN[:valid_general_url_path_chars] = /[a-z0-9!\*';:=\+\$\/%#\[\]\-_,~]/i
59
+ REGEXEN[:valid_general_url_path_chars] = /[a-z0-9!\*';:=\+\,\$\/%#\[\]\-_~]/i
65
60
  # Allow URL paths to contain balanced parens
66
61
  # 1. Used in Wikipedia URLs like /Primer_(film)
67
62
  # 2. Used in IIS sessions like /S(dfd346)/
@@ -70,22 +65,27 @@ module Twitter
70
65
  REGEXEN[:valid_url_path_chars] = /(?:
71
66
  #{REGEXEN[:wikipedia_disambiguation]}|
72
67
  @#{REGEXEN[:valid_general_url_path_chars]}+\/|
73
- [\.\,]?#{REGEXEN[:valid_general_url_path_chars]}
68
+ [\.,]#{REGEXEN[:valid_general_url_path_chars]}+|
69
+ #{REGEXEN[:valid_general_url_path_chars]}+
74
70
  )/ix
75
71
  # Valid end-of-path chracters (so /foo. does not gobble the period).
76
72
  # 1. Allow =&# for empty URL parameters and other URL-join artifacts
77
- REGEXEN[:valid_url_path_ending_chars] = /[a-z0-9=#\/]/i
73
+ REGEXEN[:valid_url_path_ending_chars] = /[a-z0-9=_#\/]|#{REGEXEN[:wikipedia_disambiguation]}/io
78
74
  REGEXEN[:valid_url_query_chars] = /[a-z0-9!\*'\(\);:&=\+\$\/%#\[\]\-_\.,~]/i
79
- REGEXEN[:valid_url_query_ending_chars] = /[a-z0-9_&=#]/i
75
+ REGEXEN[:valid_url_query_ending_chars] = /[a-z0-9_&=#\/]/i
80
76
  REGEXEN[:valid_url] = %r{
81
77
  ( # $1 total match
82
78
  (#{REGEXEN[:valid_preceding_chars]}) # $2 Preceeding chracter
83
79
  ( # $3 URL
84
- ((?:https?:\/\/|www\.)?) # $4 Protocol or beginning
80
+ (https?:\/\/) # $4 Protocol
85
81
  (#{REGEXEN[:valid_domain]}) # $5 Domain(s) and optional post number
86
- (/#{REGEXEN[:valid_url_path_chars]}*
87
- #{REGEXEN[:valid_url_path_ending_chars]}?
88
- )? # $6 URL Path
82
+ (/
83
+ (?:
84
+ #{REGEXEN[:valid_url_path_chars]}+#{REGEXEN[:valid_url_path_ending_chars]}| # 1+ path chars and a valid last char
85
+ #{REGEXEN[:valid_url_path_chars]}+#{REGEXEN[:valid_url_path_ending_chars]}?| # Optional last char to handle /@foo/ case
86
+ #{REGEXEN[:valid_url_path_ending_chars]} # Just a # case
87
+ )?
88
+ )? # $6 URL Path and anchor
89
89
  (\?#{REGEXEN[:valid_url_query_chars]}*#{REGEXEN[:valid_url_query_ending_chars]})? # $7 Query String
90
90
  )
91
91
  )
@@ -467,10 +467,9 @@ describe Twitter::Autolink do
467
467
  context "with a url lacking the protocol" do
468
468
  def original_text; "I like www.foobar.com dudes"; end
469
469
 
470
- it "links to the original text with the full href" do
470
+ it "does not link at all" do
471
471
  link = Nokogiri::HTML(@autolinked_text).search('a')
472
- link.inner_text.should == 'www.foobar.com'
473
- link.first['href'].should == 'http://www.foobar.com'
472
+ link.should be_empty
474
473
  end
475
474
  end
476
475
 
data/spec/test_urls.rb CHANGED
@@ -6,14 +6,13 @@ module TestUrls
6
6
  "http://google.com/#foo",
7
7
  "http://google.com/#search?q=iphone%20-filter%3Alinks",
8
8
  "http://twitter.com/#search?q=iphone%20-filter%3Alinks",
9
+ "http://somedomain.com/index.php?path=/abc/def/",
9
10
  "http://www.boingboing.net/2007/02/14/katamari_damacy_phon.html",
10
11
  "http://somehost.com:3000",
11
12
  "http://xo.com/~matthew+%-x",
12
13
  "http://en.wikipedia.org/wiki/Primer_(film)",
13
14
  "http://www.ams.org/bookstore-getitem/item=mbk-59",
14
15
  "http://chilp.it/?77e8fd",
15
- "www.foobar.com",
16
- "WWW.FOOBAR.COM",
17
16
  "http://tell.me/why",
18
17
  "http://longtlds.info",
19
18
  "http://✪df.ws/ejp",
@@ -28,6 +27,8 @@ module TestUrls
28
27
  INVALID = [
29
28
  "http://no-tld",
30
29
  "http://tld-too-short.x",
30
+ "www.foobar.com",
31
+ "WWW.FOOBAR.COM",
31
32
  "http://-doman_dash.com"
32
33
  ] unless defined?(TestUrls::INVALID)
33
34
 
data/twitter-text.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  spec = Gem::Specification.new do |s|
2
2
  s.name = "twitter-text"
3
- s.version = "1.2.5"
3
+ s.version = "1.3.0"
4
4
  s.authors = ["Matt Sanford", "Patrick Ewing", "Ben Cherry", "Britt Selvitelle", "Raffi Krikorian"]
5
5
  s.email = ["matt@twitter.com", "patrick.henry.ewing@gmail.com", "bcherry@gmail.com", "bs@brittspace.com", "raffi@twitter.com"]
6
6
  s.homepage = "http://twitter.com"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twitter-text
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
- - 2
9
- - 5
10
- version: 1.2.5
8
+ - 3
9
+ - 0
10
+ version: 1.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matt Sanford
@@ -19,7 +19,7 @@ autorequire:
19
19
  bindir: bin
20
20
  cert_chain: []
21
21
 
22
- date: 2010-11-18 00:00:00 -08:00
22
+ date: 2010-12-06 00:00:00 -08:00
23
23
  default_executable:
24
24
  dependencies:
25
25
  - !ruby/object:Gem::Dependency