emoji 1.0.0 → 1.0.1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +2 -2
- data/lib/emoji.rb +13 -9
- data/lib/emoji/version.rb +1 -1
- data/test/emoji_test.rb +26 -7
- data/test/string_ext_test.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a5314dfa9bd2b9fefb8db7cd2c5b52643a11615
|
4
|
+
data.tar.gz: ce8ef4dfdbf6044d5864f2ab5a4846d19bc3b36e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9dea51512846eb336698457bd4a12f6898c8b9906261b913cc720303a24f03c5c67e7666053ad00f26be58626479f71ba93642911c1a2fb33d37a45a2344630f
|
7
|
+
data.tar.gz: 847d2edef664e9949e59c71112b369d0af4ab5cdd91277d9de02fd05a35908466f1e465372e0413d4aedd188ffdc4231e1122d5f7fdfe7fce06d9f8d9e8255a3
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -41,7 +41,7 @@ Image Replacement APIs:
|
|
41
41
|
|
42
42
|
```ruby
|
43
43
|
> Emoji.replace_unicode_moji_with_images('I ❤ Emoji')
|
44
|
-
=> "I <img class=\"emoji\" src=\"http://localhost:3000/assets/emoji/heart.png\"> Emoji"
|
44
|
+
=> "I <img alt=\"❤\" class=\"emoji\" src=\"http://localhost:3000/assets/emoji/heart.png\"> Emoji"
|
45
45
|
|
46
46
|
> Emoji.image_url_for_unicode_moji('❤')
|
47
47
|
=> "http://localhost:3000/assets/emoji/heart.png"
|
@@ -81,7 +81,7 @@ and call methods directly on your string to return the same results:
|
|
81
81
|
|
82
82
|
```ruby
|
83
83
|
> 'I ❤ Emoji'.with_emoji_images
|
84
|
-
=> "I <img class=\"emoji\" src=\"http://localhost:3000/assets/emoji/heart.png\"> Emoji"
|
84
|
+
=> "I <img alt=\"❤\" class=\"emoji\" src=\"http://localhost:3000/assets/emoji/heart.png\"> Emoji"
|
85
85
|
|
86
86
|
> 'heart'.image_url
|
87
87
|
> '❤'.image_url
|
data/lib/emoji.rb
CHANGED
@@ -43,24 +43,28 @@ module Emoji
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def self.replace_unicode_moji_with_images(string)
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
if string.respond_to?(:html_safe?) && string.html_safe?
|
51
|
-
safe_string = string.dup
|
52
|
-
else
|
53
|
-
safe_string = escape_html(string.dup)
|
46
|
+
return string unless string
|
47
|
+
unless string.match(index.unicode_moji_regex)
|
48
|
+
return safe_string(string)
|
54
49
|
end
|
55
50
|
|
51
|
+
safe_string = safe_string(string.dup)
|
56
52
|
safe_string.gsub!(index.unicode_moji_regex) do |moji|
|
57
|
-
%Q{<img class="emoji" src="#{ image_url_for_unicode_moji(moji) }">}
|
53
|
+
%Q{<img alt="#{moji}" class="emoji" src="#{ image_url_for_unicode_moji(moji) }">}
|
58
54
|
end
|
59
55
|
safe_string = safe_string.html_safe if safe_string.respond_to?(:html_safe)
|
60
56
|
|
61
57
|
safe_string
|
62
58
|
end
|
63
59
|
|
60
|
+
def self.safe_string(string)
|
61
|
+
if string.respond_to?(:html_safe?) && string.html_safe?
|
62
|
+
string
|
63
|
+
else
|
64
|
+
escape_html(string)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
64
68
|
def self.escape_html(string)
|
65
69
|
@escaper.escape_html(string)
|
66
70
|
end
|
data/lib/emoji/version.rb
CHANGED
data/test/emoji_test.rb
CHANGED
@@ -46,13 +46,13 @@ describe Emoji do
|
|
46
46
|
|
47
47
|
it 'should escape html in non html_safe aware strings' do
|
48
48
|
replaced_string = Emoji.replace_unicode_moji_with_images('❤<script>')
|
49
|
-
assert_equal "<img class=\"emoji\" src=\"http://localhost:3000/heart.png\"><script>", replaced_string
|
49
|
+
assert_equal "<img alt=\"❤\" class=\"emoji\" src=\"http://localhost:3000/heart.png\"><script>", replaced_string
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'should replace unicode moji with img tag' do
|
53
53
|
base_string = "I ❤ Emoji"
|
54
54
|
replaced_string = Emoji.replace_unicode_moji_with_images(base_string)
|
55
|
-
assert_equal "I <img class=\"emoji\" src=\"http://localhost:3000/heart.png\"> Emoji", replaced_string
|
55
|
+
assert_equal "I <img alt=\"❤\" class=\"emoji\" src=\"http://localhost:3000/heart.png\"> Emoji", replaced_string
|
56
56
|
end
|
57
57
|
|
58
58
|
it 'should handle nil string' do
|
@@ -60,14 +60,24 @@ describe Emoji do
|
|
60
60
|
end
|
61
61
|
|
62
62
|
describe 'with html_safe buffer' do
|
63
|
-
it 'should escape non html_safe? strings' do
|
63
|
+
it 'should escape non html_safe? strings in emoji' do
|
64
64
|
string = HtmlSafeString.new('❤<script>')
|
65
65
|
|
66
66
|
replaced_string = string.stub(:html_safe?, false) do
|
67
67
|
Emoji.replace_unicode_moji_with_images(string)
|
68
68
|
end
|
69
69
|
|
70
|
-
assert_equal "<img class=\"emoji\" src=\"http://localhost:3000/heart.png\"><script>", replaced_string
|
70
|
+
assert_equal "<img alt=\"❤\" class=\"emoji\" src=\"http://localhost:3000/heart.png\"><script>", replaced_string
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'should escape non html_safe? strings in all strings' do
|
74
|
+
string = HtmlSafeString.new('XSS<script>')
|
75
|
+
|
76
|
+
replaced_string = string.stub(:html_safe?, false) do
|
77
|
+
Emoji.replace_unicode_moji_with_images(string)
|
78
|
+
end
|
79
|
+
|
80
|
+
assert_equal "XSS<script>", replaced_string
|
71
81
|
end
|
72
82
|
|
73
83
|
it 'should not escape html_safe strings' do
|
@@ -77,10 +87,10 @@ describe Emoji do
|
|
77
87
|
Emoji.replace_unicode_moji_with_images(string)
|
78
88
|
end
|
79
89
|
|
80
|
-
assert_equal "<img class=\"emoji\" src=\"http://localhost:3000/heart.png\"><a href=\"harmless\">", replaced_string
|
90
|
+
assert_equal "<img alt=\"❤\" class=\"emoji\" src=\"http://localhost:3000/heart.png\"><a href=\"harmless\">", replaced_string
|
81
91
|
end
|
82
92
|
|
83
|
-
it 'should always return an html_safe string' do
|
93
|
+
it 'should always return an html_safe string for emoji' do
|
84
94
|
string = HtmlSafeString.new('❤')
|
85
95
|
replaced_string = string.stub(:html_safe, 'safe_buffer') do
|
86
96
|
Emoji.replace_unicode_moji_with_images(string)
|
@@ -88,6 +98,15 @@ describe Emoji do
|
|
88
98
|
|
89
99
|
assert_equal "safe_buffer", replaced_string
|
90
100
|
end
|
101
|
+
|
102
|
+
it 'should always return an html_safe string for any string' do
|
103
|
+
string = HtmlSafeString.new('Content')
|
104
|
+
replaced_string = string.stub(:html_safe, 'safe_buffer') do
|
105
|
+
Emoji.replace_unicode_moji_with_images(string)
|
106
|
+
end
|
107
|
+
|
108
|
+
assert_equal "Content", replaced_string
|
109
|
+
end
|
91
110
|
end
|
92
111
|
end
|
93
112
|
|
@@ -108,4 +127,4 @@ describe Emoji do
|
|
108
127
|
end
|
109
128
|
end
|
110
129
|
|
111
|
-
end
|
130
|
+
end
|
data/test/string_ext_test.rb
CHANGED
@@ -7,7 +7,7 @@ describe String, 'with Emoji extensions' do
|
|
7
7
|
it 'should replace unicode moji with an img tag' do
|
8
8
|
base_string = "I ❤ Emoji"
|
9
9
|
replaced_string = base_string.with_emoji_images
|
10
|
-
assert_equal "I <img class=\"emoji\" src=\"http://localhost:3000/heart.png\"> Emoji", replaced_string
|
10
|
+
assert_equal "I <img alt=\"❤\" class=\"emoji\" src=\"http://localhost:3000/heart.png\"> Emoji", replaced_string
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: emoji
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Klabnik
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-03-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
@@ -618,7 +618,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
618
618
|
version: '0'
|
619
619
|
requirements: []
|
620
620
|
rubyforge_project:
|
621
|
-
rubygems_version: 2.0.
|
621
|
+
rubygems_version: 2.0.3
|
622
622
|
signing_key:
|
623
623
|
specification_version: 4
|
624
624
|
summary: 'A Ruby gem. For emoji. For everyone. :heart:'
|
@@ -627,4 +627,3 @@ test_files:
|
|
627
627
|
- test/index_test.rb
|
628
628
|
- test/string_ext_test.rb
|
629
629
|
- test/test_helper.rb
|
630
|
-
has_rdoc:
|