twitter-text 1.4.5 → 1.4.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -89,6 +89,7 @@ Thanks to everybody who has filed issues, provided feedback or contributed patch
89
89
  * Patrick Ewing - http://github.com/hoverbird
90
90
  * Jeff Smick - http://github.com/sprsquish
91
91
  * Kenneth Kufluk - https://github.com/kennethkufluk
92
+ * Keita Fujii - https://github.com/keitaf
92
93
 
93
94
  * Patches from the community …
94
95
  * Jean-Philippe Bougie - http://github.com/jpbougie
data/lib/autolink.rb CHANGED
@@ -137,12 +137,6 @@ module Twitter
137
137
  text = $3
138
138
  text = yield(text) if block_given?
139
139
  "#{before}<a href=\"#{options[:hashtag_url_base]}#{html_escape(text)}\" title=\"##{html_escape(text)}\" #{target_tag(options)}class=\"#{options[:url_class]} #{options[:hashtag_class]}\"#{extra_html}>#{html_escape(hash)}#{html_escape(text)}</a>"
140
- end.gsub(Twitter::Regex[:auto_link_cj_hashtags]) do
141
- before = $1
142
- hash = $2
143
- text = $3
144
- text = yield(text) if block_given?
145
- "#{before}<a href=\"#{options[:hashtag_url_base]}#{html_escape(text)}\" title=\"##{html_escape(text)}\" #{target_tag(options)}class=\"#{options[:url_class]} #{options[:hashtag_class]}\"#{extra_html}>#{html_escape(hash)}#{html_escape(text)}</a>"
146
140
  end
147
141
  end
148
142
 
data/lib/extractor.rb CHANGED
@@ -165,13 +165,6 @@ module Twitter
165
165
  :hashtag => hash_text,
166
166
  :indices => [start_position, end_position]
167
167
  }
168
- end.scan(Twitter::Regex[:auto_link_cj_hashtags]) do |before, hash, hash_text|
169
- start_position = $~.char_begin(2)
170
- end_position = $~.char_end(3)
171
- tags << {
172
- :hashtag => hash_text,
173
- :indices => [start_position, end_position]
174
- }
175
168
  end
176
169
  tags.each{|tag| yield tag[:hashtag], tag[:indices].first, tag[:indices].last } if block_given?
177
170
  tags
data/lib/regex.rb CHANGED
@@ -71,17 +71,15 @@ module Twitter
71
71
  (0x2F800..0x2FA1F).to_a # Kanji (CJK supplement)
72
72
  ].flatten.pack('U*').freeze
73
73
 
74
- CJ_BOUNDARY = /(?:\A|\z|#{REGEXEN[:spaces]}|「|」|。|\.)/
74
+ HASHTAG_BOUNDARY = /(?:\A|\z|#{REGEXEN[:spaces]}|「|」|。|\.|!)/
75
75
 
76
76
  # A hashtag must contain latin characters, numbers and underscores, but not all numbers.
77
- HASHTAG_ALPHA = /[a-z_#{LATIN_ACCENTS}#{NON_LATIN_HASHTAG_CHARS}]/io
78
- HASHTAG_ALPHANUMERIC = /[a-z0-9_#{LATIN_ACCENTS}#{NON_LATIN_HASHTAG_CHARS}]/io
77
+ HASHTAG_ALPHA = /[a-z_#{LATIN_ACCENTS}#{NON_LATIN_HASHTAG_CHARS}#{CJ_HASHTAG_CHARACTERS}]/io
78
+ HASHTAG_ALPHANUMERIC = /[a-z0-9_#{LATIN_ACCENTS}#{NON_LATIN_HASHTAG_CHARS}#{CJ_HASHTAG_CHARACTERS}]/io
79
79
 
80
- CJ_HASHTAG = /(#{CJ_BOUNDARY})(#|#)([#{CJ_HASHTAG_CHARACTERS}]+)(?=#{CJ_BOUNDARY})/o
81
- NON_CJ_HASHTAG = /(^|[^0-9A-Z&\/\?]+)(#|#)(#{HASHTAG_ALPHANUMERIC}*#{HASHTAG_ALPHA}#{HASHTAG_ALPHANUMERIC}*)/io
80
+ HASHTAG = /(#{HASHTAG_BOUNDARY})(#|#)(#{HASHTAG_ALPHANUMERIC}*#{HASHTAG_ALPHA}#{HASHTAG_ALPHANUMERIC}*)(?=#{HASHTAG_BOUNDARY})/io
82
81
 
83
- REGEXEN[:auto_link_hashtags] = /#{NON_CJ_HASHTAG}/io
84
- REGEXEN[:auto_link_cj_hashtags] = /#{CJ_HASHTAG}/io
82
+ REGEXEN[:auto_link_hashtags] = /#{HASHTAG}/io
85
83
 
86
84
  REGEXEN[:auto_link_usernames_or_lists] = /([^a-zA-Z0-9_]|^|RT:?)([@@]+)([a-zA-Z0-9_]{1,20})(\/[a-zA-Z][a-zA-Z0-9_\-]{0,24})?/o
87
85
  REGEXEN[:auto_link_emoticon] = /(8\-\#|8\-E|\+\-\(|\`\@|\`O|\&lt;\|:~\(|\}:o\{|:\-\[|\&gt;o\&lt;|X\-\/|\[:-\]\-I\-|\/\/\/\/Ö\\\\\\\\|\(\|:\|\/\)|∑:\*\)|\( \| \))/
@@ -269,19 +269,11 @@ describe Twitter::Autolink do
269
269
  end
270
270
  end
271
271
 
272
- context "with a hashtag preceded by Japanese" do
273
- def original_text; "の#twj_dev"; end
274
-
275
- it "should be linked" do
276
- @autolinked_text.should have_autolinked_hashtag('#twj_dev')
277
- end
278
- end
279
-
280
272
  context "with a hashtag followed by Japanese" do
281
273
  def original_text; "#twj_devの"; end
282
274
 
283
275
  it "should be linked" do
284
- @autolinked_text.should have_autolinked_hashtag('#twj_dev')
276
+ @autolinked_text.should have_autolinked_hashtag('#twj_dev')
285
277
  end
286
278
  end
287
279
 
@@ -228,11 +228,11 @@ describe Twitter::Extractor do
228
228
  end
229
229
 
230
230
  it "should not allow the multiplication character" do
231
- @extractor.extract_hashtags("#pre#{[0xd7].pack('U')}post").should == ["pre"]
231
+ @extractor.extract_hashtags("#pre#{[0xd7].pack('U')}post").should == []
232
232
  end
233
233
 
234
234
  it "should not allow the division character" do
235
- @extractor.extract_hashtags("#pre#{[0xf7].pack('U')}post").should == ["pre"]
235
+ @extractor.extract_hashtags("#pre#{[0xf7].pack('U')}post").should == []
236
236
  end
237
237
  end
238
238
 
@@ -253,7 +253,7 @@ describe Twitter::Extractor do
253
253
  extracted_hashtag[:indices].last.should == offset + hashtag.chars.to_a.size + 1
254
254
  end
255
255
 
256
- def no_match_hashtag_in_text(text)
256
+ def not_match_hashtag_in_text(text)
257
257
  extracted_hashtags = @extractor.extract_hashtags_with_indices(text)
258
258
  extracted_hashtags.size.should == 0
259
259
  end
@@ -283,17 +283,17 @@ describe Twitter::Extractor do
283
283
  end
284
284
 
285
285
  it "should not allow the multiplication character" do
286
- match_hashtag_in_text('pre', "#pre#{[0xd7].pack('U')}post")
286
+ not_match_hashtag_in_text("#pre#{[0xd7].pack('U')}post")
287
287
  end
288
288
 
289
289
  it "should not allow the division character" do
290
- match_hashtag_in_text('pre', "#pre#{[0xf7].pack('U')}post")
290
+ not_match_hashtag_in_text("#pre#{[0xf7].pack('U')}post")
291
291
  end
292
292
  end
293
293
  end
294
294
 
295
295
  it "should not extract numeric hashtags" do
296
- no_match_hashtag_in_text("#1234")
296
+ not_match_hashtag_in_text("#1234")
297
297
  end
298
298
  end
299
299
  end
data/spec/spec_helper.rb CHANGED
@@ -85,7 +85,7 @@ end
85
85
 
86
86
  RSpec::Matchers.define :have_autolinked_hashtag do |hashtag|
87
87
  match do |text|
88
- @link = Nokogiri::HTML(text).search("a[@href='http://twitter.com/search?q=#{CGI.escape hashtag}']")
88
+ @link = Nokogiri::HTML(text).search("a[@href='http://twitter.com/search?q=#{hashtag.sub(/^#/, '%23')}']")
89
89
  @link &&
90
90
  @link.inner_text &&
91
91
  @link.inner_text == hashtag
@@ -93,7 +93,7 @@ RSpec::Matchers.define :have_autolinked_hashtag do |hashtag|
93
93
 
94
94
  failure_message_for_should do |text|
95
95
  if @link
96
- "Expected link text to be #{hashtag}, but it was #{@link.inner_text}"
96
+ "Expected link text to be [#{hashtag}], but it was [#{@link.inner_text}] in #{text}"
97
97
  else
98
98
  "Expected hashtag #{hashtag} to be autolinked in '#{text}', but no link was found."
99
99
  end
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.4.5"
3
+ s.version = "1.4.6"
4
4
  s.authors = ["Matt Sanford", "Patrick Ewing", "Ben Cherry", "Britt Selvitelle", "Raffi Krikorian", "J.P. Cummins", "Yoshimasa Niwa"]
5
5
  s.email = ["matt@twitter.com", "patrick.henry.ewing@gmail.com", "bcherry@gmail.com", "bs@brittspace.com", "raffi@twitter.com", "jcummins@twitter.com", "niw@niw.at"]
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: 13
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 4
9
- - 5
10
- version: 1.4.5
9
+ - 6
10
+ version: 1.4.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matt Sanford