zendesk-rinku 1.7.2.1 → 1.8.0

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 CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- OTBhY2IxNDFiMWFkOGQxMzUzMjQ4MjlkYmMzZWI4MjhiODYwNGI3OQ==
5
- data.tar.gz: !binary |-
6
- OTQ1M2Y3MjE0Nzc5ODdjNmZjODVkYmVhMzdlNzc5OTlkZDUzOTA0OA==
2
+ SHA256:
3
+ metadata.gz: 54a58fb261c13b831efbcf7b02fc42867eef6cb867a45e8859e111a00cc2f7b8
4
+ data.tar.gz: ff337afc9ba30a1112a82c35bca2da168b592776ba285d3a0b16c0014a107cde
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: dd34c05b73e2c7f058b145d4bf50a1366e35cb115762c7df2fc38330b19fbc1bc74b2a224c54dbb7dfe9e3d7b92556fd77d0f88d3ef329978364942d784ad1e1
7
+ data.tar.gz: 66d41807109f60e2ffee7bf03f5557b9284b95529e12c4ec9f33fac5986345d690af296cd4dc3fc48bcb2b9ac5661ac2866b4b8cbcc29ac952205d7d38c22116
data/README.markdown CHANGED
@@ -1,3 +1,7 @@
1
+ # Rinku
2
+
3
+ Due to the absence of external maintenance, this is now a fully Zendesk owned/maintained gem.
4
+
1
5
  Rinku does linking
2
6
  ==================
3
7
 
@@ -7,7 +11,7 @@ just like the Ruby on Rails `auto_link` method -- but it's about 20 times faster
7
11
  because it's written in C, and it's about 20 times smarter when linking,
8
12
  because it does actual parsing instead of RegEx replacements.
9
13
 
10
- Rinku is a Ruby Gem
14
+ Rinku is a Ruby Gem
11
15
  -------------------
12
16
 
13
17
  Rinku is available as a Ruby gem:
@@ -16,7 +20,7 @@ Rinku is available as a Ruby gem:
16
20
 
17
21
  The Rinku source is available at GitHub:
18
22
 
19
- $ git clone git://github.com/vmg/rinku.git
23
+ $ git clone git://github.com/zendesk/rinku.git
20
24
 
21
25
  Rinku is a standalone library
22
26
  -----------------------------
@@ -53,8 +57,8 @@ the 'http://' protocol.
53
57
  HTML, Rinku is smart enough to skip the links that are already enclosed in `<a>`
54
58
  tags.`
55
59
 
56
- - `mode` is a symbol, either `:all`, `:urls` or `:email_addresses`,
57
- which specifies which kind of links will be auto-linked.
60
+ - `mode` is a symbol, either `:all`, `:urls` or `:email_addresses`,
61
+ which specifies which kind of links will be auto-linked.
58
62
 
59
63
  - `link_attr` is a string containing the link attributes for each link that
60
64
  will be generated. These attributes are not sanitized and will be include as-is
@@ -96,12 +100,21 @@ require 'rails_rinku'
96
100
  The `rails_rinku` package monkeypatches Rails with an `auto_link` method that
97
101
  mimics 100% the original one, parameter per parameter. It's just faster.
98
102
 
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.
103
+ Releasing a new version
104
+ ----------------------------------------------------
105
+ A new version is published to RubyGems.org every time a change to `version.rb` is pushed to the `main` branch.
106
+ In short, follow these steps:
107
+ 1. Update `version.rb`,
108
+ 2. run `bundle lock` to update `Gemfile.lock`,
109
+ 3. merge this change into `main`, and
110
+ 4. look at [the action](https://github.com/zendesk/rinku/actions/workflows/publish.yml) for output.
111
+
112
+ To create a pre-release from a non-main branch:
113
+ 1. change the version in `version.rb` to something like `1.2.0.pre.1` or `2.0.0.beta.2`,
114
+ 2. push this change to your branch,
115
+ 3. go to [Actions → “Publish to RubyGems.org” on GitHub](https://github.com/zendesk/rinku/actions/workflows/publish.yml),
116
+ 4. click the “Run workflow” button,
117
+ 5. pick your branch from a dropdown.
105
118
 
106
119
  Rinku has an awesome license
107
120
  ----------------------------
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'date'
2
2
  require 'rake/clean'
3
3
  require 'rake/extensiontask'
4
+ require 'bundler/setup'
5
+ require 'bundler/gem_tasks'
4
6
  require 'digest/md5'
5
7
 
6
8
  task :default => :test
@@ -18,17 +20,17 @@ Rake::ExtensionTask.new('rinku')
18
20
  require 'rake/testtask'
19
21
  Rake::TestTask.new('test') do |t|
20
22
  t.test_files = FileList['test/*_test.rb']
21
- t.ruby_opts += ['-rubygems'] if defined? Gem
23
+ t.ruby_opts += ['-r rubygems'] if defined? Gem
22
24
  end
23
25
  task 'test' => [:compile]
24
26
 
25
27
  # PACKAGING =================================================================
26
28
 
27
29
  require 'rubygems'
28
- $spec = eval(File.read('rinku.gemspec'))
30
+ $spec = Bundler::GemHelper.gemspec
29
31
 
30
32
  def package(ext='')
31
- "pkg/rinku-#{$spec.version}" + ext
33
+ "pkg/zendesk-rinku-#{$spec.version}" + ext
32
34
  end
33
35
 
34
36
  desc 'Build packages'
data/ext/rinku/autolink.c CHANGED
@@ -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
+ }
data/lib/rinku.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  module Rinku
2
- VERSION = "1.7.2"
3
2
  attr_accessor :skip_tags
4
3
  extend self
5
4
  end
data/rinku.gemspec CHANGED
@@ -1,19 +1,19 @@
1
- # encoding: UTF-8
1
+ require_relative "lib/version"
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'zendesk-rinku'
5
- s.version = '1.7.2.1'
5
+ s.version = Rinku::VERSION
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
 
11
- This is just a fork of vmg's lib with a small patch we need.
11
+ This is now a significant departure from the base gem.
12
12
  EOF
13
13
  s.email = 'shajith@zendesk.com'
14
- s.homepage = 'http://github.com/shajith/rinku'
15
- s.authors = ["Vicent Marti", "Shajith Chacko"]
16
- # = MANIFEST =
14
+ s.homepage = 'https://github.com/zendesk/rinku'
15
+ s.authors = ["Shajith Chacko", "Jonathan Cheatham", "Matt Barker"]
16
+ s.license = "ISC"
17
17
  s.files = %w[
18
18
  COPYING
19
19
  README.markdown
@@ -28,11 +28,7 @@ Gem::Specification.new do |s|
28
28
  lib/rinku.rb
29
29
  lib/rails_rinku.rb
30
30
  rinku.gemspec
31
- test/autolink_test.rb
32
31
  ]
33
- # = MANIFEST =
34
- s.test_files = ["test/autolink_test.rb"]
35
- s.extra_rdoc_files = ["COPYING"]
36
32
  s.extensions = ["ext/rinku/extconf.rb"]
37
- s.require_paths = ["lib"]
33
+ s.required_ruby_version = ">= 2.7"
38
34
  end
metadata CHANGED
@@ -1,25 +1,27 @@
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.8.0
5
5
  platform: ruby
6
6
  authors:
7
- - Vicent Marti
8
7
  - Shajith Chacko
9
- autorequire:
8
+ - Jonathan Cheatham
9
+ - Matt Barker
10
+ autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2014-04-01 00:00:00.000000000 Z
13
+ date: 2025-05-27 00:00:00.000000000 Z
13
14
  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"
15
+ description: |2
16
+ A fast and very smart autolinking library that
17
+ acts as a drop-in replacement for Rails `auto_link`
18
+
19
+ This is now a significant departure from the base gem.
17
20
  email: shajith@zendesk.com
18
21
  executables: []
19
22
  extensions:
20
23
  - ext/rinku/extconf.rb
21
- extra_rdoc_files:
22
- - COPYING
24
+ extra_rdoc_files: []
23
25
  files:
24
26
  - COPYING
25
27
  - README.markdown
@@ -34,29 +36,27 @@ files:
34
36
  - lib/rails_rinku.rb
35
37
  - lib/rinku.rb
36
38
  - rinku.gemspec
37
- - test/autolink_test.rb
38
- homepage: http://github.com/shajith/rinku
39
- licenses: []
39
+ homepage: https://github.com/zendesk/rinku
40
+ licenses:
41
+ - ISC
40
42
  metadata: {}
41
- post_install_message:
43
+ post_install_message:
42
44
  rdoc_options: []
43
45
  require_paths:
44
46
  - lib
45
47
  required_ruby_version: !ruby/object:Gem::Requirement
46
48
  requirements:
47
- - - ! '>='
49
+ - - ">="
48
50
  - !ruby/object:Gem::Version
49
- version: '0'
51
+ version: '2.7'
50
52
  required_rubygems_version: !ruby/object:Gem::Requirement
51
53
  requirements:
52
- - - ! '>='
54
+ - - ">="
53
55
  - !ruby/object:Gem::Version
54
56
  version: '0'
55
57
  requirements: []
56
- rubyforge_project:
57
- rubygems_version: 2.2.2
58
- signing_key:
58
+ rubygems_version: 3.1.6
59
+ signing_key:
59
60
  specification_version: 4
60
61
  summary: Mostly autolinking
61
- test_files:
62
- - test/autolink_test.rb
62
+ 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