zendesk-rinku 1.7.2.1 → 1.7.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- OTBhY2IxNDFiMWFkOGQxMzUzMjQ4MjlkYmMzZWI4MjhiODYwNGI3OQ==
5
- data.tar.gz: !binary |-
6
- OTQ1M2Y3MjE0Nzc5ODdjNmZjODVkYmVhMzdlNzc5OTlkZDUzOTA0OA==
2
+ SHA1:
3
+ metadata.gz: ba308c8fd36a4e3cc84e7d1af205852d4cffe215
4
+ data.tar.gz: 6a9ec10f86b857a5adbee73c94784389d70fa9d9
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- ODg4NDIxOGZjNjJkMDc2ODFmODFkZTNlNGVmZDQ1YjkyYTg4ZGY1ZDM2NTM1
10
- ZWE1ZjViMTJlNWVjOWU1YjVhOWRkZWJjNGY1ZWFhMzg3M2E4MzRkOGRkMjI4
11
- NmVlOTJmNjg5ZDkxNWQ4MTFkOTkwODk3OTQwYjdhYjYwYzZmNWQ=
12
- data.tar.gz: !binary |-
13
- YmQ1MjBkNWYzMWQ4NWU4MDI4NDg3ZmRiNDhlMTMwNzFjN2E3MTE4NjdhMDhm
14
- MGE2MDhkZjdmYTZjZGM5N2RmOGMwZmU3ZGFmYmFkN2ZhZmE2Yzg2YTNhZDRm
15
- ZDk2M2RlN2IyMjkwY2UzZTE2ZDgxYzViMTZlZWQxOTZlMDhkYjY=
6
+ metadata.gz: 93c18c020778422065b163c781711d4b93596c3b9a2ed3931f9a8ae4cec56f8f669de82fe0c28bbc65ac9b10e67228e15ea5cc5db0ad41c4a13fabf7143c1321
7
+ data.tar.gz: fc20e83c04b8f02c92f3dd2bebb21ae1436e7831925b6661bafe032d1ff131c03186b1f1404dc5755a24a3d2e5c2e30a31635994c7fe687ee765f578979d08d5
@@ -1,3 +1,6 @@
1
+ # Due to the absence of external maintenance
2
+ # this is now a fully Zendesk owned/maintained gem
3
+
1
4
  Rinku does linking
2
5
  ==================
3
6
 
@@ -16,7 +19,7 @@ Rinku is available as a Ruby gem:
16
19
 
17
20
  The Rinku source is available at GitHub:
18
21
 
19
- $ git clone git://github.com/vmg/rinku.git
22
+ $ git clone git://github.com/zendesk/rinku.git
20
23
 
21
24
  Rinku is a standalone library
22
25
  -----------------------------
@@ -96,13 +99,6 @@ require 'rails_rinku'
96
99
  The `rails_rinku` package monkeypatches Rails with an `auto_link` method that
97
100
  mimics 100% the original one, parameter per parameter. It's just faster.
98
101
 
99
- Rinku is written by me
100
- ----------------------
101
-
102
- I am Vicent Marti, and I wrote Rinku.
103
- While Rinku is busy doing autolinks, you should be busy following me on twitter.
104
- [`@vmg`](http://twitter.com/vmg). Do it.
105
-
106
102
  Rinku has an awesome license
107
103
  ----------------------------
108
104
 
data/Rakefile CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'date'
2
2
  require 'rake/clean'
3
3
  require 'rake/extensiontask'
4
+ require 'bundler/gem_tasks'
4
5
  require 'digest/md5'
5
6
 
6
7
  task :default => :test
@@ -28,7 +29,7 @@ require 'rubygems'
28
29
  $spec = eval(File.read('rinku.gemspec'))
29
30
 
30
31
  def package(ext='')
31
- "pkg/rinku-#{$spec.version}" + ext
32
+ "pkg/zendesk-rinku-#{$spec.version}" + ext
32
33
  end
33
34
 
34
35
  desc 'Build packages'
@@ -37,6 +37,9 @@
37
37
  #define strncasecmp _strnicmp
38
38
  #endif
39
39
 
40
+ int
41
+ is_unicode_space(uint8_t *data, size_t offset);
42
+
40
43
  int
41
44
  sd_autolink_issafe(const uint8_t *link, size_t link_len)
42
45
  {
@@ -78,7 +81,7 @@ autolink_delim(uint8_t *data, size_t link_end, size_t max_rewind, size_t size)
78
81
  else if (data[link_end - 1] == ';') {
79
82
  size_t new_end = link_end - 2;
80
83
 
81
- while (new_end > 0 && isalpha(data[new_end]))
84
+ while (new_end > 0 && (isalnum(data[new_end]) || data[new_end] == '#'))
82
85
  new_end--;
83
86
 
84
87
  if (new_end < link_end - 2 && data[new_end] == '&')
@@ -143,17 +146,43 @@ autolink_delim(uint8_t *data, size_t link_end, size_t max_rewind, size_t size)
143
146
  return link_end;
144
147
  }
145
148
 
149
+ static size_t
150
+ autolink_delim_iter(uint8_t *data, size_t link_end, size_t offset, size_t size)
151
+ {
152
+ size_t next_link_end;
153
+ int iterations = 0;
154
+ link_end = autolink_delim(data, link_end, offset, size);
155
+
156
+ while(link_end != 0) {
157
+ next_link_end = autolink_delim(data, link_end, offset, size);
158
+ if (next_link_end == link_end || iterations > 5) {
159
+ break;
160
+ }
161
+ link_end = next_link_end;
162
+ iterations++;
163
+ }
164
+
165
+ return link_end;
166
+ }
167
+
168
+
146
169
  static size_t
147
170
  check_domain(uint8_t *data, size_t size, int allow_short)
148
171
  {
149
172
  size_t i, np = 0;
150
173
 
151
- if (!isalnum(data[0]))
152
- return 0;
174
+ if (data[0] == '.' || data[0] == '-') return 0;
153
175
 
154
- for (i = 1; i < size - 1; ++i) {
155
- if (data[i] == '.') np++;
156
- else if (!isalnum(data[i]) && data[i] != '-') break;
176
+ for (i = 0; i < size - 1; i++) {
177
+ if (data[i] == '.') {
178
+ np++;
179
+ } else if ((data[i] >= 'a' && data[i] <= 'z')
180
+ || (data[i] >= 'A' && data[i] <= 'Z')
181
+ || (data[i] >= '0' && data[i] <= '9')
182
+ || (data[i] == '-')) {
183
+ } else {
184
+ break;
185
+ }
157
186
  }
158
187
 
159
188
  if (allow_short) {
@@ -188,16 +217,23 @@ sd_autolink__www(
188
217
 
189
218
  link_end = check_domain(data, size, 0);
190
219
 
191
- if (link_end == 0)
220
+ if (link_end == 0) {
192
221
  return 0;
222
+ } else if (data[link_end] > 127) {
223
+ if (!is_unicode_space(data, link_end)) {
224
+ /* we prevent linking a domain that contains unicode
225
+ * in case of sneaky lookalike attacks */
226
+ return 0;
227
+ }
228
+ } else {
229
+ while (link_end < size && !is_unicode_space(data, link_end)) {
230
+ link_end++;
231
+ }
232
+ }
193
233
 
194
- while (link_end < size && !isspace(data[link_end]))
195
- link_end++;
196
-
197
- link_end = autolink_delim(data, link_end, max_rewind, size);
234
+ link_end = autolink_delim_iter(data, link_end, max_rewind, size);
198
235
 
199
- if (link_end == 0)
200
- return 0;
236
+ if (link_end == 0) { return 0; }
201
237
 
202
238
  bufput(link, data, link_end);
203
239
  *rewind_p = 0;
@@ -249,7 +285,7 @@ sd_autolink__email(
249
285
  if (link_end < 2 || nb != 1 || np == 0)
250
286
  return 0;
251
287
 
252
- link_end = autolink_delim(data, link_end, max_rewind, size);
288
+ link_end = autolink_delim_iter(data, link_end, max_rewind, size);
253
289
 
254
290
  if (link_end == 0)
255
291
  return 0;
@@ -291,10 +327,16 @@ sd_autolink__url(
291
327
  return 0;
292
328
 
293
329
  link_end += domain_len;
294
- while (link_end < size && !isspace(data[link_end]))
295
- link_end++;
296
330
 
297
- link_end = autolink_delim(data, link_end, max_rewind, size);
331
+ if (data[link_end] > 127) {
332
+ if (!is_unicode_space(data, link_end)) { return 0; }
333
+ } else {
334
+ while (link_end < size && !is_unicode_space(data, link_end)) {
335
+ link_end++;
336
+ }
337
+ }
338
+
339
+ link_end = autolink_delim_iter(data, link_end, max_rewind, size);
298
340
 
299
341
  if (link_end == 0)
300
342
  return 0;
@@ -304,3 +346,40 @@ sd_autolink__url(
304
346
 
305
347
  return link_end;
306
348
  }
349
+
350
+ int
351
+ is_unicode_space(uint8_t *data, size_t offset) {
352
+
353
+ if(isspace(data[offset])) {
354
+ return 1;
355
+ }
356
+
357
+ /* Unicode Whitespace list from https://en.wikipedia.org/wiki/Whitespace_character#Unicode */
358
+ if (data[offset] == 0xE2) {
359
+ if (data[offset+1] == 0x80) {
360
+ if (data[offset+2] >= 0x80 && data[offset+2] <= 0x8C) {
361
+ return 1;
362
+ } else if (data[offset+2] == 0xA8 || data[offset+2] == 0xA9 || data[offset+2] == 0xAF) {
363
+ return 1;
364
+ }
365
+ } else if (data[offset+1] == 0x81) {
366
+ if (data[offset+2] == 0x9F) {
367
+ return 1;
368
+ }
369
+ }
370
+ } else if (data[offset] == 0xE3) {
371
+ if (data[offset+1] == 0x80) {
372
+ if (data[offset+2] == 0x80) {
373
+ return 1;
374
+ }
375
+ }
376
+ } else if (data[offset] == 0xEF) {
377
+ if (data[offset+1] == 0xBB) {
378
+ if (data[offset+2] == 0xBF) {
379
+ return 1;
380
+ }
381
+ }
382
+ }
383
+
384
+ return 0;
385
+ }
@@ -1,5 +1,5 @@
1
1
  module Rinku
2
- VERSION = "1.7.2"
2
+ VERSION = "1.7.3"
3
3
  attr_accessor :skip_tags
4
4
  extend self
5
5
  end
@@ -1,19 +1,17 @@
1
- # encoding: UTF-8
2
-
3
1
  Gem::Specification.new do |s|
4
2
  s.name = 'zendesk-rinku'
5
- s.version = '1.7.2.1'
3
+ s.version = '1.7.3'
6
4
  s.summary = "Mostly autolinking"
7
5
  s.description = <<-EOF
8
6
  A fast and very smart autolinking library that
9
7
  acts as a drop-in replacement for Rails `auto_link`
10
8
 
11
- This is just a fork of vmg's lib with a small patch we need.
9
+ This is now a significant departure from the base gem.
12
10
  EOF
13
11
  s.email = 'shajith@zendesk.com'
14
- s.homepage = 'http://github.com/shajith/rinku'
15
- s.authors = ["Vicent Marti", "Shajith Chacko"]
16
- # = MANIFEST =
12
+ s.homepage = 'https://github.com/zendesk/rinku'
13
+ s.authors = ["Shajith Chacko", "Jonathan Cheatham", "Matt Barker"]
14
+ s.license = "ISC"
17
15
  s.files = %w[
18
16
  COPYING
19
17
  README.markdown
@@ -28,11 +26,8 @@ Gem::Specification.new do |s|
28
26
  lib/rinku.rb
29
27
  lib/rails_rinku.rb
30
28
  rinku.gemspec
31
- test/autolink_test.rb
32
29
  ]
33
- # = MANIFEST =
34
- s.test_files = ["test/autolink_test.rb"]
35
- s.extra_rdoc_files = ["COPYING"]
36
30
  s.extensions = ["ext/rinku/extconf.rb"]
37
- s.require_paths = ["lib"]
31
+ s.add_development_dependency "rake"
32
+ s.add_development_dependency "rake-compiler"
38
33
  end
metadata CHANGED
@@ -1,25 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zendesk-rinku
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.2.1
4
+ version: 1.7.3
5
5
  platform: ruby
6
6
  authors:
7
- - Vicent Marti
8
7
  - Shajith Chacko
8
+ - Jonathan Cheatham
9
+ - Matt Barker
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2014-04-01 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\n This is just a fork of vmg's lib
16
- with a small patch we need.\n"
13
+ date: 2016-06-16 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rake
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: rake-compiler
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ description: |2
44
+ A fast and very smart autolinking library that
45
+ acts as a drop-in replacement for Rails `auto_link`
46
+
47
+ This is now a significant departure from the base gem.
17
48
  email: shajith@zendesk.com
18
49
  executables: []
19
50
  extensions:
20
51
  - ext/rinku/extconf.rb
21
- extra_rdoc_files:
22
- - COPYING
52
+ extra_rdoc_files: []
23
53
  files:
24
54
  - COPYING
25
55
  - README.markdown
@@ -34,9 +64,9 @@ files:
34
64
  - lib/rails_rinku.rb
35
65
  - lib/rinku.rb
36
66
  - rinku.gemspec
37
- - test/autolink_test.rb
38
- homepage: http://github.com/shajith/rinku
39
- licenses: []
67
+ homepage: https://github.com/zendesk/rinku
68
+ licenses:
69
+ - ISC
40
70
  metadata: {}
41
71
  post_install_message:
42
72
  rdoc_options: []
@@ -44,19 +74,18 @@ require_paths:
44
74
  - lib
45
75
  required_ruby_version: !ruby/object:Gem::Requirement
46
76
  requirements:
47
- - - ! '>='
77
+ - - ">="
48
78
  - !ruby/object:Gem::Version
49
79
  version: '0'
50
80
  required_rubygems_version: !ruby/object:Gem::Requirement
51
81
  requirements:
52
- - - ! '>='
82
+ - - ">="
53
83
  - !ruby/object:Gem::Version
54
84
  version: '0'
55
85
  requirements: []
56
86
  rubyforge_project:
57
- rubygems_version: 2.2.2
87
+ rubygems_version: 2.4.5.1
58
88
  signing_key:
59
89
  specification_version: 4
60
90
  summary: Mostly autolinking
61
- test_files:
62
- - test/autolink_test.rb
91
+ test_files: []
@@ -1,318 +0,0 @@
1
- # encoding: utf-8
2
- rootdir = File.dirname(File.dirname(__FILE__))
3
- $LOAD_PATH.unshift "#{rootdir}/lib"
4
-
5
- require 'test/unit'
6
- require 'cgi'
7
- require 'uri'
8
- require 'rinku'
9
-
10
- class RedcarpetAutolinkTest < Test::Unit::TestCase
11
-
12
- SAFE_CHARS = "{}[]~'"
13
-
14
- def assert_linked(expected, url)
15
- assert_equal expected, Rinku.auto_link(url)
16
- end
17
-
18
- def test_segfault
19
- Rinku.auto_link("a+b@d.com+e@f.com", mode=:all)
20
- end
21
-
22
- def test_escapes_quotes
23
- assert_linked %(<a href="http://website.com/&quot;onmouseover=document.body.style.backgroundColor=&quot;pink&quot;;//">http://website.com/"onmouseover=document.body.style.backgroundColor="pink";//</a>),
24
- %(http://website.com/"onmouseover=document.body.style.backgroundColor="pink";//)
25
- end
26
-
27
- def test_global_skip_tags
28
- assert_equal Rinku.skip_tags, nil
29
- Rinku.skip_tags = ['pre']
30
- assert_equal Rinku.skip_tags, ['pre']
31
-
32
- Rinku.skip_tags = ['pa']
33
- url = 'This is just a <pa>http://www.pokemon.com</pa> test'
34
- assert_equal Rinku.auto_link(url), url
35
-
36
- Rinku.skip_tags = nil
37
- assert_not_equal Rinku.auto_link(url), url
38
- end
39
-
40
- def test_auto_link_with_single_trailing_punctuation_and_space
41
- url = "http://www.youtube.com"
42
- url_result = generate_result(url)
43
- assert_equal url_result, Rinku.auto_link(url)
44
- assert_equal "link: #{url_result}. foo?", Rinku.auto_link("link: #{url}. foo?")
45
- end
46
-
47
- def test_does_not_segfault
48
- assert_linked "< this is just a test", "< this is just a test"
49
- end
50
-
51
- def test_skips_tags
52
- html = <<-html
53
- This is just a test. http://www.pokemon.com
54
- <div>
55
- More test
56
- http://www.amd.com
57
- </div>
58
- <pre>
59
- CODE www.less.es
60
- </pre>
61
- html
62
-
63
- result = <<-result
64
- This is just a test. <a href="http://www.pokemon.com">http://www.pokemon.com</a>
65
- <div>
66
- More test
67
- http://www.amd.com
68
- </div>
69
- <pre>
70
- CODE <a href="http://www.less.es">www.less.es</a>
71
- </pre>
72
- result
73
- assert_equal result, Rinku.auto_link(html, :all, nil, ["div", "a"])
74
- end
75
-
76
- def test_auto_link_with_brackets
77
- link1_raw = 'http://en.wikipedia.org/wiki/Sprite_(computer_graphics)'
78
- link1_result = generate_result(link1_raw)
79
- assert_equal link1_result, Rinku.auto_link(link1_raw)
80
- assert_equal "(link: #{link1_result})", Rinku.auto_link("(link: #{link1_raw})")
81
-
82
- link2_raw = 'http://en.wikipedia.org/wiki/Sprite_[computer_graphics]'
83
- link2_result = generate_result(link2_raw)
84
- assert_equal link2_result, Rinku.auto_link(link2_raw)
85
- assert_equal "[link: #{link2_result}]", Rinku.auto_link("[link: #{link2_raw}]")
86
-
87
- link3_raw = 'http://en.wikipedia.org/wiki/Sprite_{computer_graphics}'
88
- link3_result = generate_result(link3_raw)
89
- assert_equal link3_result, Rinku.auto_link(link3_raw)
90
- assert_equal "{link: #{link3_result}}", Rinku.auto_link("{link: #{link3_raw}}")
91
- end
92
-
93
- def test_auto_link_with_multiple_trailing_punctuations
94
- url = "http://youtube.com"
95
- url_result = generate_result(url)
96
- assert_equal url_result, Rinku.auto_link(url)
97
- assert_equal "(link: #{url_result}).", Rinku.auto_link("(link: #{url}).")
98
- end
99
-
100
- def test_auto_link_with_block
101
- url = "http://api.rubyonrails.com/Foo.html"
102
- email = "fantabulous@shiznadel.ic"
103
-
104
- assert_equal %(<p><a href="#{url}">#{url[0...7]}...</a><br /><a href="mailto:#{email}">#{email[0...7]}...</a><br /></p>), Rinku.auto_link("<p>#{url}<br />#{email}<br /></p>") { |_url| _url[0...7] + '...'}
105
- end
106
-
107
- def test_auto_link_with_block_with_html
108
- pic = "http://example.com/pic.png"
109
- url = "http://example.com/album?a&b=c"
110
-
111
- expect = %(My pic: <a href="#{pic}"><img src="#{pic}" width="160px"></a> -- full album here #{generate_result(url)})
112
- text = "My pic: #{pic} -- full album here #{CGI.escapeHTML url}"
113
-
114
- assert_equal expect, Rinku.auto_link(text) { |link|
115
- if link =~ /\.(jpg|gif|png|bmp|tif)$/i
116
- %(<img src="#{link}" width="160px">)
117
- else
118
- link
119
- end
120
- }
121
- end
122
-
123
- def test_auto_link_already_linked
124
- linked1 = generate_result('Ruby On Rails', 'http://www.rubyonrails.com')
125
- linked2 = %('<a href="http://www.example.com">www.example.com</a>')
126
- linked3 = %('<a href="http://www.example.com" rel="nofollow">www.example.com</a>')
127
- linked4 = %('<a href="http://www.example.com"><b>www.example.com</b></a>')
128
- linked5 = %('<a href="#close">close</a> <a href="http://www.example.com"><b>www.example.com</b></a>')
129
- assert_equal linked1, Rinku.auto_link(linked1)
130
- assert_equal linked2, Rinku.auto_link(linked2)
131
- assert_equal linked3, Rinku.auto_link(linked3)
132
- assert_equal linked4, Rinku.auto_link(linked4)
133
- assert_equal linked5, Rinku.auto_link(linked5)
134
-
135
- linked_email = %Q(<a href="mailto:david@loudthinking.com">Mail me</a>)
136
- assert_equal linked_email, Rinku.auto_link(linked_email)
137
- end
138
-
139
-
140
- def test_auto_link_at_eol
141
- url1 = "http://api.rubyonrails.com/Foo.html"
142
- url2 = "http://www.ruby-doc.org/core/Bar.html"
143
-
144
- assert_equal %(<p><a href="#{url1}">#{url1}</a><br /><a href="#{url2}">#{url2}</a><br /></p>), Rinku.auto_link("<p>#{url1}<br />#{url2}<br /></p>")
145
- end
146
-
147
- def test_block
148
- link = Rinku.auto_link("Find ur favorite pokeman @ http://www.pokemon.com") do |url|
149
- assert_equal url, "http://www.pokemon.com"
150
- "POKEMAN WEBSITE"
151
- end
152
-
153
- assert_equal link, "Find ur favorite pokeman @ <a href=\"http://www.pokemon.com\">POKEMAN WEBSITE</a>"
154
- end
155
-
156
- def test_links_with_cyrillic_x
157
- url = "http://example.com/х"
158
-
159
- assert_linked "<a href=\"#{url}\">#{url}</a>", url
160
- end
161
-
162
- def test_autolink_works
163
- url = "http://example.com/"
164
- assert_linked "<a href=\"#{url}\">#{url}</a>", url
165
- end
166
-
167
- def test_autolink_options_for_short_domains
168
- url = "http://google"
169
- linked_url = "<a href=\"#{url}\">#{url}</a>"
170
- flags = Rinku::AUTOLINK_SHORT_DOMAINS
171
-
172
- # Specifying use short_domains in the args
173
- url = "http://google"
174
- linked_url = "<a href=\"#{url}\">#{url}</a>"
175
- assert_equal Rinku.auto_link(url, nil, nil, nil, flags), linked_url
176
-
177
- # Specifying no short_domains in the args
178
- url = "http://google"
179
- linked_url = "<a href=\"#{url}\">#{url}</a>"
180
- assert_equal Rinku.auto_link(url, nil, nil, nil, 0), url
181
- end
182
-
183
- def test_not_autolink_www
184
- assert_linked "Awww... man", "Awww... man"
185
- end
186
-
187
- def test_does_not_terminate_on_dash
188
- url = "http://example.com/Notification_Center-GitHub-20101108-140050.jpg"
189
- assert_linked "<a href=\"#{url}\">#{url}</a>", url
190
- end
191
-
192
- def test_does_not_include_trailing_gt
193
- url = "http://example.com"
194
- assert_linked "&lt;<a href=\"#{url}\">#{url}</a>&gt;", "&lt;#{url}&gt;"
195
- end
196
-
197
- def test_links_with_anchors
198
- url = "https://github.com/github/hubot/blob/master/scripts/cream.js#L20-20"
199
- assert_linked "<a href=\"#{url}\">#{url}</a>", url
200
- end
201
-
202
- def test_links_like_rails
203
- urls = %w(http://www.rubyonrails.com
204
- http://www.rubyonrails.com:80
205
- http://www.rubyonrails.com/~minam
206
- https://www.rubyonrails.com/~minam
207
- http://www.rubyonrails.com/~minam/url%20with%20spaces
208
- http://www.rubyonrails.com/foo.cgi?something=here
209
- http://www.rubyonrails.com/foo.cgi?something=here&and=here
210
- http://www.rubyonrails.com/contact;new
211
- http://www.rubyonrails.com/contact;new%20with%20spaces
212
- http://www.rubyonrails.com/contact;new?with=query&string=params
213
- http://www.rubyonrails.com/~minam/contact;new?with=query&string=params
214
- http://en.wikipedia.org/wiki/Wikipedia:Today%27s_featured_picture_%28animation%29/January_20%2C_2007
215
- http://www.mail-archive.com/rails@lists.rubyonrails.org/
216
- http://www.amazon.com/Testing-Equal-Sign-In-Path/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1198861734&sr=8-1
217
- http://en.wikipedia.org/wiki/Sprite_(computer_graphics)
218
- http://en.wikipedia.org/wiki/Texas_hold%27em
219
- https://www.google.com/doku.php?id=gps:resource:scs:start
220
- )
221
-
222
- urls.each do |url|
223
- assert_linked %(<a href="#{CGI.escapeHTML url}">#{CGI.escapeHTML url}</a>), CGI.escapeHTML(url)
224
- end
225
- end
226
-
227
- def test_links_like_autolink_rails
228
- email_raw = 'david@loudthinking.com'
229
- email_result = %{<a href="mailto:#{email_raw}">#{email_raw}</a>}
230
- email2_raw = '+david@loudthinking.com'
231
- email2_result = %{<a href="mailto:#{email2_raw}">#{email2_raw}</a>}
232
- link_raw = 'http://www.rubyonrails.com'
233
- link_result = %{<a href="#{link_raw}">#{link_raw}</a>}
234
- link_result_with_options = %{<a href="#{link_raw}" target="_blank">#{link_raw}</a>}
235
- link2_raw = 'www.rubyonrails.com'
236
- link2_result = %{<a href="http://#{link2_raw}">#{link2_raw}</a>}
237
- link3_raw = 'http://manuals.ruby-on-rails.com/read/chapter.need_a-period/103#page281'
238
- link3_result = %{<a href="#{link3_raw}">#{link3_raw}</a>}
239
- link4_raw = CGI.escapeHTML 'http://foo.example.com/controller/action?parm=value&p2=v2#anchor123'
240
- link4_result = %{<a href="#{link4_raw}">#{link4_raw}</a>}
241
- link5_raw = 'http://foo.example.com:3000/controller/action'
242
- link5_result = %{<a href="#{link5_raw}">#{link5_raw}</a>}
243
- link6_raw = 'http://foo.example.com:3000/controller/action+pack'
244
- link6_result = %{<a href="#{link6_raw}">#{link6_raw}</a>}
245
- link7_raw = CGI.escapeHTML 'http://foo.example.com/controller/action?parm=value&p2=v2#anchor-123'
246
- link7_result = %{<a href="#{link7_raw}">#{link7_raw}</a>}
247
- link8_raw = 'http://foo.example.com:3000/controller/action.html'
248
- link8_result = %{<a href="#{link8_raw}">#{link8_raw}</a>}
249
- link9_raw = 'http://business.timesonline.co.uk/article/0,,9065-2473189,00.html'
250
- link9_result = %{<a href="#{link9_raw}">#{link9_raw}</a>}
251
- link10_raw = 'http://www.mail-archive.com/ruby-talk@ruby-lang.org/'
252
- link10_result = %{<a href="#{link10_raw}">#{link10_raw}</a>}
253
-
254
- assert_linked %(Go to #{link_result} and say hello to #{email_result}), "Go to #{link_raw} and say hello to #{email_raw}"
255
- assert_linked %(<p>Link #{link_result}</p>), "<p>Link #{link_raw}</p>"
256
- assert_linked %(<p>#{link_result} Link</p>), "<p>#{link_raw} Link</p>"
257
- assert_linked %(Go to #{link_result}.), %(Go to #{link_raw}.)
258
- assert_linked %(<p>Go to #{link_result}, then say hello to #{email_result}.</p>), %(<p>Go to #{link_raw}, then say hello to #{email_raw}.</p>)
259
- assert_linked %(<p>Link #{link2_result}</p>), "<p>Link #{link2_raw}</p>"
260
- assert_linked %(<p>#{link2_result} Link</p>), "<p>#{link2_raw} Link</p>"
261
- assert_linked %(Go to #{link2_result}.), %(Go to #{link2_raw}.)
262
- assert_linked %(<p>Say hello to #{email_result}, then go to #{link2_result},</p>), %(<p>Say hello to #{email_raw}, then go to #{link2_raw},</p>)
263
- assert_linked %(<p>Link #{link3_result}</p>), "<p>Link #{link3_raw}</p>"
264
- assert_linked %(<p>#{link3_result} Link</p>), "<p>#{link3_raw} Link</p>"
265
- assert_linked %(Go to #{link3_result}.), %(Go to #{link3_raw}.)
266
- assert_linked %(<p>Go to #{link3_result}. seriously, #{link3_result}? i think I'll say hello to #{email_result}. instead.</p>), %(<p>Go to #{link3_raw}. seriously, #{link3_raw}? i think I'll say hello to #{email_raw}. instead.</p>)
267
- assert_linked %(<p>Link #{link4_result}</p>), "<p>Link #{link4_raw}</p>"
268
- assert_linked %(<p>#{link4_result} Link</p>), "<p>#{link4_raw} Link</p>"
269
- assert_linked %(<p>#{link5_result} Link</p>), "<p>#{link5_raw} Link</p>"
270
- assert_linked %(<p>#{link6_result} Link</p>), "<p>#{link6_raw} Link</p>"
271
- assert_linked %(<p>#{link7_result} Link</p>), "<p>#{link7_raw} Link</p>"
272
- assert_linked %(<p>Link #{link8_result}</p>), "<p>Link #{link8_raw}</p>"
273
- assert_linked %(<p>#{link8_result} Link</p>), "<p>#{link8_raw} Link</p>"
274
- assert_linked %(Go to #{link8_result}.), %(Go to #{link8_raw}.)
275
- assert_linked %(<p>Go to #{link8_result}. seriously, #{link8_result}? i think I'll say hello to #{email_result}. instead.</p>), %(<p>Go to #{link8_raw}. seriously, #{link8_raw}? i think I'll say hello to #{email_raw}. instead.</p>)
276
- assert_linked %(<p>Link #{link9_result}</p>), "<p>Link #{link9_raw}</p>"
277
- assert_linked %(<p>#{link9_result} Link</p>), "<p>#{link9_raw} Link</p>"
278
- assert_linked %(Go to #{link9_result}.), %(Go to #{link9_raw}.)
279
- assert_linked %(<p>Go to #{link9_result}. seriously, #{link9_result}? i think I'll say hello to #{email_result}. instead.</p>), %(<p>Go to #{link9_raw}. seriously, #{link9_raw}? i think I'll say hello to #{email_raw}. instead.</p>)
280
- assert_linked %(<p>#{link10_result} Link</p>), "<p>#{link10_raw} Link</p>"
281
- assert_linked email2_result, email2_raw
282
- assert_linked "#{link_result} #{link_result} #{link_result}", "#{link_raw} #{link_raw} #{link_raw}"
283
- assert_linked '<a href="http://www.rubyonrails.com">Ruby On Rails</a>', '<a href="http://www.rubyonrails.com">Ruby On Rails</a>'
284
- end
285
-
286
- if "".respond_to?(:force_encoding)
287
- def test_copies_source_encoding
288
- str = "http://www.bash.org"
289
-
290
- ret = Rinku.auto_link str
291
- assert_equal str.encoding, ret.encoding
292
-
293
- str.encode! 'binary'
294
-
295
- ret = Rinku.auto_link str
296
- assert_equal str.encoding, ret.encoding
297
- end
298
-
299
- def test_block_encoding
300
- url = "http://example.com/х"
301
- assert_equal "UTF-8", url.encoding.to_s
302
-
303
- link = Rinku.auto_link(url) do |u|
304
- assert_equal "UTF-8", u.encoding.to_s
305
- u
306
- end
307
-
308
- assert_equal link.encoding.to_s, "UTF-8"
309
- end
310
-
311
- end
312
-
313
- def generate_result(link_text, href = nil)
314
- href ||= link_text
315
- %{<a href="#{CGI.escapeHTML href}">#{CGI.escapeHTML link_text}</a>}
316
- end
317
-
318
- end