twitter-text 1.2.1 → 1.2.2

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/Rakefile CHANGED
@@ -11,7 +11,7 @@ require 'digest'
11
11
 
12
12
  spec = Gem::Specification.new do |s|
13
13
  s.name = "twitter-text"
14
- s.version = "1.2.1"
14
+ s.version = "1.2.2"
15
15
  s.authors = ["Matt Sanford", "Patrick Ewing", "Ben Cherry", "Britt Selvitelle", "Raffi Krikorian"]
16
16
  s.email = ["matt@twitter.com", "patrick.henry.ewing@gmail.com", "bcherry@gmail.com", "bs@brittspace.com", "raffi@twitter.com"]
17
17
  s.homepage = "http://twitter.com"
data/lib/autolink.rb CHANGED
@@ -24,7 +24,7 @@ module Twitter
24
24
  "'" => '''
25
25
  }
26
26
 
27
- def encode(text)
27
+ def html_escape(text)
28
28
  text && text.gsub(/[&"'><]/) do |character|
29
29
  HTML_ENTITIES[character]
30
30
  end
@@ -88,7 +88,7 @@ module Twitter
88
88
  # the link is a list
89
89
  chunk = list = "#{user}#{slash_listname}"
90
90
  chunk = yield(list) if block_given?
91
- "#{before}#{at}<a class=\"#{options[:url_class]} #{options[:list_class]}\" href=\"#{encode(options[:list_url_base])}#{encode(list.downcase)}\"#{extra_html}>#{encode(chunk)}</a>"
91
+ "#{before}#{at}<a class=\"#{options[:url_class]} #{options[:list_class]}\" href=\"#{html_escape(options[:list_url_base])}#{html_escape(list.downcase)}\"#{extra_html}>#{html_escape(chunk)}</a>"
92
92
  else
93
93
  if after =~ Twitter::Regex[:end_screen_name_match]
94
94
  # Followed by something that means we don't autolink
@@ -97,7 +97,7 @@ module Twitter
97
97
  # this is a screen name
98
98
  chunk = user
99
99
  chunk = yield(chunk) if block_given?
100
- "#{before}#{at}<a class=\"#{options[:url_class]} #{options[:username_class]}\" href=\"#{encode(options[:username_url_base])}#{encode(chunk)}\"#{extra_html}>#{encode(chunk)}</a>"
100
+ "#{before}#{at}<a class=\"#{options[:url_class]} #{options[:username_class]}\" href=\"#{html_escape(options[:username_url_base])}#{html_escape(chunk)}\"#{extra_html}>#{html_escape(chunk)}</a>"
101
101
  end
102
102
  end
103
103
  end
@@ -126,7 +126,7 @@ module Twitter
126
126
  hash = $2
127
127
  text = $3
128
128
  text = yield(text) if block_given?
129
- "#{before}<a href=\"#{options[:hashtag_url_base]}#{encode(text)}\" title=\"##{encode(text)}\" class=\"#{options[:url_class]} #{options[:hashtag_class]}\"#{extra_html}>#{encode(hash)}#{encode(text)}</a>"
129
+ "#{before}<a href=\"#{options[:hashtag_url_base]}#{html_escape(text)}\" title=\"##{html_escape(text)}\" class=\"#{options[:url_class]} #{options[:hashtag_class]}\"#{extra_html}>#{html_escape(hash)}#{html_escape(text)}</a>"
130
130
  end
131
131
  end
132
132
 
@@ -143,7 +143,7 @@ module Twitter
143
143
  if !protocol.blank? || domain =~ Twitter::Regex[:probable_tld]
144
144
  html_attrs = tag_options(options.stringify_keys) || ""
145
145
  full_url = ((protocol =~ Twitter::Regex[:www] || protocol.blank?) ? "http://#{url}" : url)
146
- "#{before}<a href=\"#{encode(full_url)}\"#{html_attrs}>#{encode(url)}</a>"
146
+ "#{before}<a href=\"#{html_escape(full_url)}\"#{html_attrs}>#{html_escape(url)}</a>"
147
147
  else
148
148
  all
149
149
  end
@@ -518,22 +518,22 @@ describe Twitter::Autolink do
518
518
 
519
519
  end
520
520
 
521
- describe "encode" do
521
+ describe "html_escape" do
522
522
  before do
523
523
  @linker = TestAutolink.new
524
524
  end
525
525
  it "should escape html entities properly" do
526
- @linker.encode("&").should == "&amp;"
527
- @linker.encode(">").should == "&gt;"
528
- @linker.encode("<").should == "&lt;"
529
- @linker.encode("\"").should == "&quot;"
530
- @linker.encode("'").should == "&#39;"
531
- @linker.encode("&<>\"").should == "&amp;&lt;&gt;&quot;"
532
- @linker.encode("<div>").should == "&lt;div&gt;"
533
- @linker.encode("a&b").should == "a&amp;b"
534
- @linker.encode("<a href=\"http://twitter.com\" target=\"_blank\">twitter & friends</a>").should == "&lt;a href=&quot;http://twitter.com&quot; target=&quot;_blank&quot;&gt;twitter &amp; friends&lt;/a&gt;"
535
- @linker.encode("&amp;").should == "&amp;amp;"
536
- @linker.encode(nil).should == nil
526
+ @linker.html_escape("&").should == "&amp;"
527
+ @linker.html_escape(">").should == "&gt;"
528
+ @linker.html_escape("<").should == "&lt;"
529
+ @linker.html_escape("\"").should == "&quot;"
530
+ @linker.html_escape("'").should == "&#39;"
531
+ @linker.html_escape("&<>\"").should == "&amp;&lt;&gt;&quot;"
532
+ @linker.html_escape("<div>").should == "&lt;div&gt;"
533
+ @linker.html_escape("a&b").should == "a&amp;b"
534
+ @linker.html_escape("<a href=\"http://twitter.com\" target=\"_blank\">twitter & friends</a>").should == "&lt;a href=&quot;http://twitter.com&quot; target=&quot;_blank&quot;&gt;twitter &amp; friends&lt;/a&gt;"
535
+ @linker.html_escape("&amp;").should == "&amp;amp;"
536
+ @linker.html_escape(nil).should == nil
537
537
  end
538
538
  end
539
539
 
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: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 2
9
- - 1
10
- version: 1.2.1
9
+ - 2
10
+ version: 1.2.2
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-10-05 00:00:00 -07:00
22
+ date: 2010-10-08 00:00:00 -07:00
23
23
  default_executable:
24
24
  dependencies:
25
25
  - !ruby/object:Gem::Dependency