rinku 1.7.3 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,187 @@
1
+ #include <stdlib.h>
2
+ #include <stdint.h>
3
+ #include <assert.h>
4
+ #include <stdbool.h>
5
+
6
+ #include "utf8.h"
7
+
8
+ /** 1 = space, 2 = punct, 3 = digit, 4 = alpha, 0 = other
9
+ */
10
+ static const uint8_t ctype_class[256] = {
11
+ /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */
12
+ /* 0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0,
13
+ /* 1 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
14
+ /* 2 */ 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
15
+ /* 3 */ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2,
16
+ /* 4 */ 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
17
+ /* 5 */ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 2, 2, 2,
18
+ /* 6 */ 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
19
+ /* 7 */ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 2, 2, 0,
20
+ /* 8 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
21
+ /* 9 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
22
+ /* a */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
23
+ /* b */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
24
+ /* c */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
25
+ /* d */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
26
+ /* e */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
27
+ /* f */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
28
+
29
+ bool rinku_isspace(char c) { return ctype_class[(uint8_t)c] == 1; }
30
+ bool rinku_ispunct(char c) { return ctype_class[(uint8_t)c] == 2; }
31
+ bool rinku_isdigit(char c) { return ctype_class[(uint8_t)c] == 3; }
32
+ bool rinku_isalpha(char c) { return ctype_class[(uint8_t)c] == 4; }
33
+ bool rinku_isalnum(char c)
34
+ {
35
+ uint8_t cls = ctype_class[(uint8_t)c];
36
+ return (cls == 3 || cls == 4);
37
+ }
38
+
39
+ static const int8_t utf8proc_utf8class[256] = {
40
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
41
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
42
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
43
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
44
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
45
+ 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
46
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
47
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
48
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
49
+ 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
50
+ 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0};
51
+
52
+ static int32_t read_cp(const uint8_t *str, int8_t length)
53
+ {
54
+ switch (length) {
55
+ case 1:
56
+ return str[0];
57
+ case 2:
58
+ return ((str[0] & 0x1F) << 6) + (str[1] & 0x3F);
59
+ case 3:
60
+ return ((str[0] & 0x0F) << 12) + ((str[1] & 0x3F) << 6) +
61
+ (str[2] & 0x3F);
62
+ case 4:
63
+ return ((str[0] & 0x07) << 18) + ((str[1] & 0x3F) << 12) +
64
+ ((str[2] & 0x3F) << 6) + (str[3] & 0x3F);
65
+ default:
66
+ return 0xFFFD; // replacement character
67
+ }
68
+ }
69
+
70
+ int32_t utf8proc_next(const uint8_t *str, size_t *pos)
71
+ {
72
+ const size_t p = *pos;
73
+ const int8_t length = utf8proc_utf8class[str[p]];
74
+ (*pos) += length;
75
+ return read_cp(str + p, length);
76
+ }
77
+
78
+ size_t utf8proc_find_space(const uint8_t *str, size_t pos, size_t size)
79
+ {
80
+ while (pos < size) {
81
+ const size_t last = pos;
82
+ int32_t uc = utf8proc_next(str, &pos);
83
+ if (utf8proc_is_space(uc))
84
+ return last;
85
+ }
86
+ return size;
87
+ }
88
+
89
+ int32_t utf8proc_rewind(const uint8_t *data, size_t pos)
90
+ {
91
+ int8_t length = 0;
92
+
93
+ if (!pos)
94
+ return 0x0;
95
+
96
+ if ((data[pos - 1] & 0xC0) == 0x0)
97
+ return data[pos - 1];
98
+
99
+ if (pos > 1 && utf8proc_utf8class[data[pos - 2]] == 2)
100
+ length = 2;
101
+ else if (pos > 2 && utf8proc_utf8class[data[pos - 3]] == 3)
102
+ length = 3;
103
+ else if (pos > 3 && utf8proc_utf8class[data[pos - 4]] == 4)
104
+ length = 4;
105
+
106
+ return read_cp(&data[pos - length], length);
107
+ }
108
+
109
+ bool utf8proc_is_space(int32_t uc)
110
+ {
111
+ return (uc == 9 || uc == 10 || uc == 12 || uc == 13 ||
112
+ uc == 32 || uc == 160 || uc == 5760 ||
113
+ (uc >= 8192 && uc <= 8202) || uc == 8239 ||
114
+ uc == 8287 || uc == 12288);
115
+ }
116
+
117
+ bool utf8proc_is_punctuation(int32_t uc)
118
+ {
119
+ if (uc < 128)
120
+ return rinku_ispunct(uc);
121
+
122
+ return
123
+ (uc == 161 || uc == 167 || uc == 171 || uc == 182 ||
124
+ uc == 183 || uc == 187 || uc == 191 || uc == 894 ||
125
+ uc == 903 || (uc >= 1370 && uc <= 1375) || uc == 1417 ||
126
+ uc == 1418 || uc == 1470 || uc == 1472 || uc == 1475 ||
127
+ uc == 1478 || uc == 1523 || uc == 1524 || uc == 1545 ||
128
+ uc == 1546 || uc == 1548 || uc == 1549 || uc == 1563 ||
129
+ uc == 1566 || uc == 1567 || (uc >= 1642 && uc <= 1645) ||
130
+ uc == 1748 || (uc >= 1792 && uc <= 1805) ||
131
+ (uc >= 2039 && uc <= 2041) || (uc >= 2096 && uc <= 2110) ||
132
+ uc == 2142 || uc == 2404 || uc == 2405 || uc == 2416 ||
133
+ uc == 2800 || uc == 3572 || uc == 3663 || uc == 3674 ||
134
+ uc == 3675 || (uc >= 3844 && uc <= 3858) || uc == 3860 ||
135
+ (uc >= 3898 && uc <= 3901) || uc == 3973 ||
136
+ (uc >= 4048 && uc <= 4052) || uc == 4057 || uc == 4058 ||
137
+ (uc >= 4170 && uc <= 4175) || uc == 4347 ||
138
+ (uc >= 4960 && uc <= 4968) || uc == 5120 || uc == 5741 ||
139
+ uc == 5742 || uc == 5787 || uc == 5788 ||
140
+ (uc >= 5867 && uc <= 5869) || uc == 5941 || uc == 5942 ||
141
+ (uc >= 6100 && uc <= 6102) || (uc >= 6104 && uc <= 6106) ||
142
+ (uc >= 6144 && uc <= 6154) || uc == 6468 || uc == 6469 ||
143
+ uc == 6686 || uc == 6687 || (uc >= 6816 && uc <= 6822) ||
144
+ (uc >= 6824 && uc <= 6829) || (uc >= 7002 && uc <= 7008) ||
145
+ (uc >= 7164 && uc <= 7167) || (uc >= 7227 && uc <= 7231) ||
146
+ uc == 7294 || uc == 7295 || (uc >= 7360 && uc <= 7367) ||
147
+ uc == 7379 || (uc >= 8208 && uc <= 8231) ||
148
+ (uc >= 8240 && uc <= 8259) || (uc >= 8261 && uc <= 8273) ||
149
+ (uc >= 8275 && uc <= 8286) || uc == 8317 || uc == 8318 ||
150
+ uc == 8333 || uc == 8334 || (uc >= 8968 && uc <= 8971) ||
151
+ uc == 9001 || uc == 9002 || (uc >= 10088 && uc <= 10101) ||
152
+ uc == 10181 || uc == 10182 || (uc >= 10214 && uc <= 10223) ||
153
+ (uc >= 10627 && uc <= 10648) || (uc >= 10712 && uc <= 10715) ||
154
+ uc == 10748 || uc == 10749 || (uc >= 11513 && uc <= 11516) ||
155
+ uc == 11518 || uc == 11519 || uc == 11632 ||
156
+ (uc >= 11776 && uc <= 11822) || (uc >= 11824 && uc <= 11842) ||
157
+ (uc >= 12289 && uc <= 12291) || (uc >= 12296 && uc <= 12305) ||
158
+ (uc >= 12308 && uc <= 12319) || uc == 12336 || uc == 12349 ||
159
+ uc == 12448 || uc == 12539 || uc == 42238 || uc == 42239 ||
160
+ (uc >= 42509 && uc <= 42511) || uc == 42611 || uc == 42622 ||
161
+ (uc >= 42738 && uc <= 42743) || (uc >= 43124 && uc <= 43127) ||
162
+ uc == 43214 || uc == 43215 || (uc >= 43256 && uc <= 43258) ||
163
+ uc == 43310 || uc == 43311 || uc == 43359 ||
164
+ (uc >= 43457 && uc <= 43469) || uc == 43486 || uc == 43487 ||
165
+ (uc >= 43612 && uc <= 43615) || uc == 43742 || uc == 43743 ||
166
+ uc == 43760 || uc == 43761 || uc == 44011 || uc == 64830 ||
167
+ uc == 64831 || (uc >= 65040 && uc <= 65049) ||
168
+ (uc >= 65072 && uc <= 65106) || (uc >= 65108 && uc <= 65121) ||
169
+ uc == 65123 || uc == 65128 || uc == 65130 || uc == 65131 ||
170
+ (uc >= 65281 && uc <= 65283) || (uc >= 65285 && uc <= 65290) ||
171
+ (uc >= 65292 && uc <= 65295) || uc == 65306 || uc == 65307 ||
172
+ uc == 65311 || uc == 65312 || (uc >= 65339 && uc <= 65341) ||
173
+ uc == 65343 || uc == 65371 || uc == 65373 ||
174
+ (uc >= 65375 && uc <= 65381) || (uc >= 65792 && uc <= 65794) ||
175
+ uc == 66463 || uc == 66512 || uc == 66927 || uc == 67671 ||
176
+ uc == 67871 || uc == 67903 || (uc >= 68176 && uc <= 68184) ||
177
+ uc == 68223 || (uc >= 68336 && uc <= 68342) ||
178
+ (uc >= 68409 && uc <= 68415) || (uc >= 68505 && uc <= 68508) ||
179
+ (uc >= 69703 && uc <= 69709) || uc == 69819 || uc == 69820 ||
180
+ (uc >= 69822 && uc <= 69825) || (uc >= 69952 && uc <= 69955) ||
181
+ uc == 70004 || uc == 70005 || (uc >= 70085 && uc <= 70088) ||
182
+ uc == 70093 || (uc >= 70200 && uc <= 70205) || uc == 70854 ||
183
+ (uc >= 71105 && uc <= 71113) || (uc >= 71233 && uc <= 71235) ||
184
+ (uc >= 74864 && uc <= 74868) || uc == 92782 || uc == 92783 ||
185
+ uc == 92917 || (uc >= 92983 && uc <= 92987) || uc == 92996 ||
186
+ uc == 113823);
187
+ }
@@ -0,0 +1,34 @@
1
+ /*
2
+ * Copyright (c) 2016, GitHub, Inc
3
+ *
4
+ * Permission to use, copy, modify, and distribute this software for any
5
+ * purpose with or without fee is hereby granted, provided that the above
6
+ * copyright notice and this permission notice appear in all copies.
7
+ *
8
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
+ */
16
+ #ifndef RINKU_UTF8_H
17
+ #define RINKU_UTF8_H
18
+
19
+ #include <stdint.h>
20
+ #include <stdbool.h>
21
+
22
+ bool rinku_isspace(char c);
23
+ bool rinku_ispunct(char c);
24
+ bool rinku_isdigit(char c);
25
+ bool rinku_isalpha(char c);
26
+ bool rinku_isalnum(char c);
27
+
28
+ int32_t utf8proc_rewind(const uint8_t *data, size_t pos);
29
+ size_t utf8proc_find_space(const uint8_t *str, size_t pos, size_t size);
30
+
31
+ bool utf8proc_is_space(int32_t uc);
32
+ bool utf8proc_is_punctuation(int32_t uc);
33
+
34
+ #endif
@@ -1,7 +1,11 @@
1
1
  module Rinku
2
2
  VERSION = "1.7.3"
3
- attr_accessor :skip_tags
4
- extend self
3
+
4
+ class << self
5
+ attr_accessor :skip_tags
6
+ end
7
+
8
+ self.skip_tags = nil
5
9
  end
6
10
 
7
11
  require 'rinku.so'
@@ -2,29 +2,32 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'rinku'
5
- s.version = '1.7.3'
5
+ s.version = '2.0.0'
6
6
  s.summary = "Mostly autolinking"
7
7
  s.description = <<-EOF
8
8
  A fast and very smart autolinking library that
9
9
  acts as a drop-in replacement for Rails `auto_link`
10
10
  EOF
11
11
  s.email = 'vicent@github.com'
12
- s.homepage = 'http://github.com/vmg/rinku'
12
+ s.homepage = 'https://github.com/vmg/rinku'
13
13
  s.authors = ["Vicent Marti"]
14
14
  # = MANIFEST =
15
15
  s.files = %w[
16
16
  COPYING
17
17
  README.markdown
18
18
  Rakefile
19
- ext/rinku/rinku.c
20
- ext/rinku/rinku.h
21
19
  ext/rinku/autolink.c
22
20
  ext/rinku/autolink.h
23
21
  ext/rinku/buffer.c
24
22
  ext/rinku/buffer.h
25
23
  ext/rinku/extconf.rb
26
- lib/rinku.rb
24
+ ext/rinku/rinku.c
25
+ ext/rinku/rinku.h
26
+ ext/rinku/rinku_rb.c
27
+ ext/rinku/utf8.c
28
+ ext/rinku/utf8.h
27
29
  lib/rails_rinku.rb
30
+ lib/rinku.rb
28
31
  rinku.gemspec
29
32
  test/autolink_test.rb
30
33
  ]
@@ -33,4 +36,8 @@ Gem::Specification.new do |s|
33
36
  s.extra_rdoc_files = ["COPYING"]
34
37
  s.extensions = ["ext/rinku/extconf.rb"]
35
38
  s.require_paths = ["lib"]
39
+
40
+ s.add_development_dependency "rake"
41
+ s.add_development_dependency "rake-compiler"
42
+ s.add_development_dependency "minitest"
36
43
  end
@@ -2,21 +2,24 @@
2
2
  rootdir = File.dirname(File.dirname(__FILE__))
3
3
  $LOAD_PATH.unshift "#{rootdir}/lib"
4
4
 
5
- require 'test/unit'
5
+ require 'minitest/autorun'
6
6
  require 'cgi'
7
7
  require 'uri'
8
8
  require 'rinku'
9
9
 
10
- class RedcarpetAutolinkTest < Test::Unit::TestCase
11
-
12
- SAFE_CHARS = "{}[]~'"
10
+ class RinkuAutoLinkTest < Minitest::Test
11
+ def generate_result(link_text, href = nil)
12
+ href ||= link_text
13
+ href = "http://" + href unless href =~ %r{\A\w+://}
14
+ %{<a href="#{CGI.escapeHTML href}">#{CGI.escapeHTML link_text}</a>}
15
+ end
13
16
 
14
17
  def assert_linked(expected, url)
15
18
  assert_equal expected, Rinku.auto_link(url)
16
19
  end
17
20
 
18
21
  def test_segfault
19
- Rinku.auto_link("a+b@d.com+e@f.com", mode=:all)
22
+ Rinku.auto_link("a+b@d.com+e@f.com", :all)
20
23
  end
21
24
 
22
25
  def test_escapes_quotes
@@ -34,7 +37,7 @@ class RedcarpetAutolinkTest < Test::Unit::TestCase
34
37
  assert_equal Rinku.auto_link(url), url
35
38
 
36
39
  Rinku.skip_tags = nil
37
- assert_not_equal Rinku.auto_link(url), url
40
+ refute_equal Rinku.auto_link(url), url
38
41
  end
39
42
 
40
43
  def test_auto_link_with_single_trailing_punctuation_and_space
@@ -46,6 +49,11 @@ class RedcarpetAutolinkTest < Test::Unit::TestCase
46
49
  end
47
50
  end
48
51
 
52
+ def test_terminates_on_ampersand
53
+ url = "http://example.com"
54
+ assert_linked "hello &#39;<a href=\"#{url}\">#{url}</a>&#39; hello", "hello &#39;#{url}&#39; hello"
55
+ end
56
+
49
57
  def test_does_not_segfault
50
58
  assert_linked "< this is just a test", "< this is just a test"
51
59
  end
@@ -227,7 +235,6 @@ This is just a test. <a href="http://www.pokemon.com">http://www.pokemon.com</a>
227
235
  email2_result = %{<a href="mailto:#{email2_raw}">#{email2_raw}</a>}
228
236
  link_raw = 'http://www.rubyonrails.com'
229
237
  link_result = %{<a href="#{link_raw}">#{link_raw}</a>}
230
- link_result_with_options = %{<a href="#{link_raw}" target="_blank">#{link_raw}</a>}
231
238
  link2_raw = 'www.rubyonrails.com'
232
239
  link2_result = %{<a href="http://#{link2_raw}">#{link2_raw}</a>}
233
240
  link3_raw = 'http://manuals.ruby-on-rails.com/read/chapter.need_a-period/103#page281'
@@ -279,23 +286,94 @@ This is just a test. <a href="http://www.pokemon.com">http://www.pokemon.com</a>
279
286
  assert_linked '<a href="http://www.rubyonrails.com">Ruby On Rails</a>', '<a href="http://www.rubyonrails.com">Ruby On Rails</a>'
280
287
  end
281
288
 
282
- if "".respond_to?(:force_encoding)
283
- def test_copies_source_encoding
284
- str = "http://www.bash.org"
289
+ def test_copies_source_encoding
290
+ str = "http://www.bash.org"
291
+
292
+ ret = Rinku.auto_link str
293
+ assert_equal str.encoding, ret.encoding
294
+
295
+ str.encode! 'binary'
296
+
297
+ ret = Rinku.auto_link str
298
+ assert_equal str.encoding, ret.encoding
299
+ end
300
+
301
+ def test_valid_encodings_are_generated
302
+ str = "&lt;a href=&#39;http://gi.co&#39;&gt;gi.co&lt;/a&gt;\xC2\xA0r"
303
+ assert_equal Encoding::UTF_8, str.encoding
304
+
305
+ res = Rinku.auto_link(str)
306
+ assert_equal Encoding::UTF_8, res.encoding
307
+ assert res.valid_encoding?
308
+ end
309
+
310
+ def test_polish_wikipedia_haha
311
+ url = "https://pl.wikipedia.org/wiki/Komisja_śledcza_do_zbadania_sprawy_zarzutu_nielegalnego_wywierania_wpływu_na_funkcjonariuszy_policji,_służb_specjalnych,_prokuratorów_i_osoby_pełniące_funkcje_w_organach_wymiaru_sprawiedliwości"
312
+ input = "A wikipedia link (#{url})"
313
+ expected = "A wikipedia link (<a href=\"#{url}\">#{url}</a>)"
285
314
 
286
- ret = Rinku.auto_link str
287
- assert_equal str.encoding, ret.encoding
315
+ assert_linked expected, input
316
+ end
288
317
 
289
- str.encode! 'binary'
318
+ def test_only_valid_encodings_are_accepted
319
+ str = "this is invalid \xA0 utf8"
320
+ assert_equal Encoding::UTF_8, str.encoding
321
+ assert !str.valid_encoding?
290
322
 
291
- ret = Rinku.auto_link str
292
- assert_equal str.encoding, ret.encoding
323
+ assert_raises ArgumentError do
324
+ Rinku.auto_link(str)
293
325
  end
294
326
  end
295
327
 
296
- def generate_result(link_text, href = nil)
297
- href ||= link_text
298
- %{<a href="#{CGI.escapeHTML href}">#{CGI.escapeHTML link_text}</a>}
328
+ NBSP = "\xC2\xA0".freeze
329
+
330
+ def test_the_famous_nbsp
331
+ input = "at http://google.com/#{NBSP};"
332
+ expected = "at <a href=\"http://google.com/\">http://google.com/</a>#{NBSP};"
333
+ assert_linked expected, input
334
+ end
335
+
336
+ def test_does_not_include_trailing_nonbreaking_spaces
337
+ url = "http://example.com/"
338
+ assert_linked "<a href=\"#{url}\">#{url}</a>#{NBSP}and", "#{url}#{NBSP}and"
339
+ end
340
+
341
+ def test_identifies_preceeding_nonbreaking_spaces
342
+ url = "http://example.com/"
343
+ assert_linked "#{NBSP}<a href=\"#{url}\">#{url}</a> and", "#{NBSP}#{url} and"
299
344
  end
300
345
 
346
+ def test_urls_with_2_wide_UTF8_characters
347
+ url = "http://example.com/?foo=¥&bar=1"
348
+ assert_linked "<a href=\"#{url}\">#{url}</a> and", "#{url} and"
349
+ end
350
+
351
+ def test_urls_with_4_wide_UTF8_characters
352
+ url = "http://example.com/?foo=&bar=1"
353
+ assert_linked "<a href=\"#{url}\">#{url}</a> and", "#{url} and"
354
+ end
355
+
356
+ def test_handles_urls_with_emoji_properly
357
+ url = "http://foo.com/💖a"
358
+ assert_linked "<a href=\"#{url}\">#{url}</a> and", "#{url} and"
359
+ end
360
+
361
+ def test_identifies_nonbreaking_spaces_preceeding_emails
362
+ email_raw = 'david@loudthinking.com'
363
+ assert_linked "email#{NBSP}<a href=\"mailto:#{email_raw}\">#{email_raw}</a>", "email#{NBSP}#{email_raw}"
364
+ end
365
+
366
+ def test_www_is_case_insensitive
367
+ url = "www.reddit.com"
368
+ assert_linked generate_result(url), url
369
+
370
+ url = "WWW.REDDIT.COM"
371
+ assert_linked generate_result(url), url
372
+
373
+ url = "Www.reddit.Com"
374
+ assert_linked generate_result(url), url
375
+
376
+ url = "WwW.reddit.CoM"
377
+ assert_linked generate_result(url), url
378
+ end
301
379
  end
metadata CHANGED
@@ -1,18 +1,60 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rinku
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.3
5
- prerelease:
4
+ version: 2.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Vicent Marti
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-04-25 00:00:00.000000000 Z
13
- dependencies: []
14
- description: ! " A fast and very smart autolinking library that\n acts as a
15
- drop-in replacement for Rails `auto_link`\n"
11
+ date: 2016-05-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake-compiler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: |2
56
+ A fast and very smart autolinking library that
57
+ acts as a drop-in replacement for Rails `auto_link`
16
58
  email: vicent@github.com
17
59
  executables: []
18
60
  extensions:
@@ -23,40 +65,42 @@ files:
23
65
  - COPYING
24
66
  - README.markdown
25
67
  - Rakefile
26
- - ext/rinku/rinku.c
27
- - ext/rinku/rinku.h
28
68
  - ext/rinku/autolink.c
29
69
  - ext/rinku/autolink.h
30
70
  - ext/rinku/buffer.c
31
71
  - ext/rinku/buffer.h
32
72
  - ext/rinku/extconf.rb
33
- - lib/rinku.rb
73
+ - ext/rinku/rinku.c
74
+ - ext/rinku/rinku.h
75
+ - ext/rinku/rinku_rb.c
76
+ - ext/rinku/utf8.c
77
+ - ext/rinku/utf8.h
34
78
  - lib/rails_rinku.rb
79
+ - lib/rinku.rb
35
80
  - rinku.gemspec
36
81
  - test/autolink_test.rb
37
- homepage: http://github.com/vmg/rinku
82
+ homepage: https://github.com/vmg/rinku
38
83
  licenses: []
84
+ metadata: {}
39
85
  post_install_message:
40
86
  rdoc_options: []
41
87
  require_paths:
42
88
  - lib
43
89
  required_ruby_version: !ruby/object:Gem::Requirement
44
- none: false
45
90
  requirements:
46
- - - ! '>='
91
+ - - ">="
47
92
  - !ruby/object:Gem::Version
48
93
  version: '0'
49
94
  required_rubygems_version: !ruby/object:Gem::Requirement
50
- none: false
51
95
  requirements:
52
- - - ! '>='
96
+ - - ">="
53
97
  - !ruby/object:Gem::Version
54
98
  version: '0'
55
99
  requirements: []
56
100
  rubyforge_project:
57
- rubygems_version: 1.8.23
101
+ rubygems_version: 2.2.5
58
102
  signing_key:
59
- specification_version: 3
103
+ specification_version: 4
60
104
  summary: Mostly autolinking
61
105
  test_files:
62
106
  - test/autolink_test.rb