zendesk-rinku 1.7.0 → 1.7.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NjJhYWM1MmUzNzc3MDI5NzliOWYxMDg0MWUyZTQzYzUxNzU0NmQ4Yw==
4
+ OTBhY2IxNDFiMWFkOGQxMzUzMjQ4MjlkYmMzZWI4MjhiODYwNGI3OQ==
5
5
  data.tar.gz: !binary |-
6
- ZDg3N2VhMzc0MDc5MDQ1ZGFmYzAwNjJiNDk2MDVhYmQ4ZjA2OWViYg==
6
+ OTQ1M2Y3MjE0Nzc5ODdjNmZjODVkYmVhMzdlNzc5OTlkZDUzOTA0OA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NTI4ODlhMjg1OTRlODc3OGRhMDlmMDM2ZGYxMzk5YWFhMjdlYzE3M2NkZjUz
10
- Nzg1NTFiZGEyMzQ2ZDkzZDA0NzIwYTE2YmRmM2IzMmRiNzg4ZDU3YWJjOTcw
11
- YjgwYmI5ZGVmNjJmMjBjOGYzNDg5NWM3MDUwMGUzNjVmMTM4NDc=
9
+ ODg4NDIxOGZjNjJkMDc2ODFmODFkZTNlNGVmZDQ1YjkyYTg4ZGY1ZDM2NTM1
10
+ ZWE1ZjViMTJlNWVjOWU1YjVhOWRkZWJjNGY1ZWFhMzg3M2E4MzRkOGRkMjI4
11
+ NmVlOTJmNjg5ZDkxNWQ4MTFkOTkwODk3OTQwYjdhYjYwYzZmNWQ=
12
12
  data.tar.gz: !binary |-
13
- OTYxZTNmYjlkNWU3NGZjZmMxZDYxMmIzYjNkMWQ2YmIwNWY1M2MyOGYxYmZh
14
- Yjc1ZWUwNjgxOWU1Y2JkN2NkY2ZiYzU5OGFmNWM3OGU1MDBjZjQ5ZmFlMjBi
15
- NDkxNTRkYTc2NTM0Nzg1NTY0ZThmYmZhNDhjMDkxOWU2NTUwZWI=
13
+ YmQ1MjBkNWYzMWQ4NWU4MDI4NDg3ZmRiNDhlMTMwNzFjN2E3MTE4NjdhMDhm
14
+ MGE2MDhkZjdmYTZjZGM5N2RmOGMwZmU3ZGFmYmFkN2ZhZmE2Yzg2YTNhZDRm
15
+ ZDk2M2RlN2IyMjkwY2UzZTE2ZDgxYzViMTZlZWQxOTZlMDhkYjY=
data/Rakefile CHANGED
@@ -50,7 +50,7 @@ file package('.gem') => %w[pkg/ rinku.gemspec] + $spec.files do |f|
50
50
  end
51
51
 
52
52
  # GEMSPEC HELPERS ==========================================================
53
- task :gather => 'sundown/src/autolink.h' do |t|
53
+ task :gather => 'sundown:checkout' do |t|
54
54
  files =
55
55
  FileList[
56
56
  'sundown/src/{buffer,autolink}.h',
@@ -61,7 +61,9 @@ task :gather => 'sundown/src/autolink.h' do |t|
61
61
  :verbose => true
62
62
  end
63
63
 
64
-
65
- file 'sundown/src/autolink.h' do |t|
66
- abort "The Sundown submodule is required."
64
+ task 'sundown:checkout' do |t|
65
+ unless File.exists?('sundown/src/markdown.h')
66
+ sh 'git submodule init'
67
+ sh 'git submodule update'
68
+ end
67
69
  end
data/ext/rinku/autolink.c CHANGED
@@ -20,7 +20,18 @@
20
20
  #include <string.h>
21
21
  #include <stdlib.h>
22
22
  #include <stdio.h>
23
+ #include "ruby.h"
24
+
25
+ #ifdef HAVE_RUBY_ENCODING_H
26
+ #include <ruby/encoding.h>
27
+ #define isalnum(s) rb_isalnum(s)
28
+ #define isspace(s) rb_isspace(s)
29
+ #define isalpha(s) rb_isalpha(s)
30
+ #define ispunct(s) rb_ispunct(s)
31
+ #else
23
32
  #include <ctype.h>
33
+ #endif
34
+
24
35
 
25
36
  #if defined(_WIN32)
26
37
  #define strncasecmp _strnicmp
@@ -49,7 +60,7 @@ sd_autolink_issafe(const uint8_t *link, size_t link_len)
49
60
  }
50
61
 
51
62
  static size_t
52
- autolink_delim(uint8_t *data, size_t link_end, size_t offset, size_t size)
63
+ autolink_delim(uint8_t *data, size_t link_end, size_t max_rewind, size_t size)
53
64
  {
54
65
  uint8_t cclose, copen = 0;
55
66
  size_t i;
@@ -163,13 +174,13 @@ sd_autolink__www(
163
174
  size_t *rewind_p,
164
175
  struct buf *link,
165
176
  uint8_t *data,
166
- size_t offset,
177
+ size_t max_rewind,
167
178
  size_t size,
168
179
  unsigned int flags)
169
180
  {
170
181
  size_t link_end;
171
182
 
172
- if (offset > 0 && !ispunct(data[-1]) && !isspace(data[-1]))
183
+ if (max_rewind > 0 && !ispunct(data[-1]) && !isspace(data[-1]))
173
184
  return 0;
174
185
 
175
186
  if (size < 4 || memcmp(data, "www.", strlen("www.")) != 0)
@@ -183,7 +194,7 @@ sd_autolink__www(
183
194
  while (link_end < size && !isspace(data[link_end]))
184
195
  link_end++;
185
196
 
186
- link_end = autolink_delim(data, link_end, offset, size);
197
+ link_end = autolink_delim(data, link_end, max_rewind, size);
187
198
 
188
199
  if (link_end == 0)
189
200
  return 0;
@@ -199,14 +210,14 @@ sd_autolink__email(
199
210
  size_t *rewind_p,
200
211
  struct buf *link,
201
212
  uint8_t *data,
202
- size_t offset,
213
+ size_t max_rewind,
203
214
  size_t size,
204
215
  unsigned int flags)
205
216
  {
206
217
  size_t link_end, rewind;
207
218
  int nb = 0, np = 0;
208
219
 
209
- for (rewind = 0; rewind < offset; ++rewind) {
220
+ for (rewind = 0; rewind < max_rewind; ++rewind) {
210
221
  uint8_t c = data[-rewind - 1];
211
222
 
212
223
  if (isalnum(c))
@@ -238,7 +249,7 @@ sd_autolink__email(
238
249
  if (link_end < 2 || nb != 1 || np == 0)
239
250
  return 0;
240
251
 
241
- link_end = autolink_delim(data, link_end, offset, size);
252
+ link_end = autolink_delim(data, link_end, max_rewind, size);
242
253
 
243
254
  if (link_end == 0)
244
255
  return 0;
@@ -254,7 +265,7 @@ sd_autolink__url(
254
265
  size_t *rewind_p,
255
266
  struct buf *link,
256
267
  uint8_t *data,
257
- size_t offset,
268
+ size_t max_rewind,
258
269
  size_t size,
259
270
  unsigned int flags)
260
271
  {
@@ -263,7 +274,7 @@ sd_autolink__url(
263
274
  if (size < 4 || data[1] != '/' || data[2] != '/')
264
275
  return 0;
265
276
 
266
- while (rewind < offset && isalpha(data[-rewind - 1]))
277
+ while (rewind < max_rewind && isalpha(data[-rewind - 1]))
267
278
  rewind++;
268
279
 
269
280
  if (!sd_autolink_issafe(data - rewind, size + rewind))
@@ -283,7 +294,7 @@ sd_autolink__url(
283
294
  while (link_end < size && !isspace(data[link_end]))
284
295
  link_end++;
285
296
 
286
- link_end = autolink_delim(data, link_end, offset, size);
297
+ link_end = autolink_delim(data, link_end, max_rewind, size);
287
298
 
288
299
  if (link_end == 0)
289
300
  return 0;
@@ -293,4 +304,3 @@ sd_autolink__url(
293
304
 
294
305
  return link_end;
295
306
  }
296
-
data/ext/rinku/rinku.c CHANGED
@@ -24,6 +24,8 @@
24
24
  #include <ruby/encoding.h>
25
25
  #else
26
26
  #define rb_enc_copy(dst, src)
27
+ #define rb_enc_set_index(str, idx)
28
+ #define rb_enc_get_index(str) 1
27
29
  #endif
28
30
 
29
31
  #include "autolink.h"
@@ -74,7 +76,7 @@ static const char *g_hrefs[] = {
74
76
  };
75
77
 
76
78
  static void
77
- autolink__print(struct buf *ob, const struct buf *link, void *payload)
79
+ autolink__print(struct buf *ob, const struct buf *link, void *payload, int enc_index)
78
80
  {
79
81
  bufput(ob, link->data, link->size);
80
82
  }
@@ -191,10 +193,11 @@ rinku_autolink(
191
193
  unsigned int flags,
192
194
  const char *link_attr,
193
195
  const char **skip_tags,
194
- void (*link_text_cb)(struct buf *ob, const struct buf *link, void *payload),
196
+ void (*link_text_cb)(struct buf *ob, const struct buf *link, void *payload, int enc_index),
197
+ int enc_index,
195
198
  void *payload)
196
199
  {
197
- size_t i, end;
200
+ size_t i, end, last_link_found = 0;
198
201
  struct buf *link = bufnew(16);
199
202
  char active_chars[256];
200
203
  void (*link_url_cb)(struct buf *, const struct buf *, void *);
@@ -249,8 +252,11 @@ rinku_autolink(
249
252
  }
250
253
 
251
254
  link->size = 0;
255
+
252
256
  link_end = g_callbacks[(int)action](
253
- &rewind, link, (uint8_t *)text + end, end, size - end, flags);
257
+ &rewind, link, (uint8_t *)text + end,
258
+ end - last_link_found,
259
+ size - end, flags);
254
260
 
255
261
  /* print the link */
256
262
  if (link_end > 0) {
@@ -267,12 +273,12 @@ rinku_autolink(
267
273
  BUFPUTSL(ob, "\">");
268
274
  }
269
275
 
270
- link_text_cb(ob, link, payload);
276
+ link_text_cb(ob, link, payload, enc_index);
271
277
  BUFPUTSL(ob, "</a>");
272
278
 
273
279
  link_count++;
274
280
  i = end + link_end;
275
- end = i;
281
+ last_link_found = end = i;
276
282
  } else {
277
283
  end = end + 1;
278
284
  }
@@ -287,10 +293,11 @@ rinku_autolink(
287
293
  * Ruby code
288
294
  */
289
295
  static void
290
- autolink_callback(struct buf *link_text, const struct buf *link, void *block)
296
+ autolink_callback(struct buf *link_text, const struct buf *link, void *block, int enc_index)
291
297
  {
292
298
  VALUE rb_link, rb_link_text;
293
299
  rb_link = rb_str_new(link->data, link->size);
300
+ rb_enc_set_index(rb_link, enc_index);
294
301
  rb_link_text = rb_funcall((VALUE)block, rb_intern("call"), 1, rb_link);
295
302
  Check_Type(rb_link_text, T_STRING);
296
303
  bufput(link_text, RSTRING_PTR(rb_link_text), RSTRING_LEN(rb_link_text));
@@ -346,8 +353,8 @@ const char **rinku_load_tags(VALUE rb_skip)
346
353
  * HTML, Rinku is smart enough to skip the links that are already enclosed in `<a>`
347
354
  * tags.`
348
355
  *
349
- * - `mode` is a symbol, either `:all`, `:urls` or `:email_addresses`,
350
- * which specifies which kind of links will be auto-linked.
356
+ * - `mode` is a symbol, either `:all`, `:urls` or `:email_addresses`,
357
+ * which specifies which kind of links will be auto-linked.
351
358
  *
352
359
  * - `link_attr` is a string containing the link attributes for each link that
353
360
  * will be generated. These attributes are not sanitized and will be include as-is
@@ -392,7 +399,7 @@ rb_rinku_autolink(int argc, VALUE *argv, VALUE self)
392
399
  ID mode_sym;
393
400
 
394
401
  rb_scan_args(argc, argv, "14&", &rb_text, &rb_mode,
395
- &rb_html, &rb_skip, &rb_flags, &rb_block);
402
+ &rb_html, &rb_skip, &rb_flags, &rb_block);
396
403
 
397
404
  Check_Type(rb_text, T_STRING);
398
405
 
@@ -434,6 +441,7 @@ rb_rinku_autolink(int argc, VALUE *argv, VALUE self)
434
441
  rb_raise(rb_eTypeError,
435
442
  "Invalid linking mode (possible values are :all, :urls, :email_addresses)");
436
443
 
444
+
437
445
  count = rinku_autolink(
438
446
  output_buf,
439
447
  RSTRING_PTR(rb_text),
@@ -443,6 +451,7 @@ rb_rinku_autolink(int argc, VALUE *argv, VALUE self)
443
451
  link_attr,
444
452
  skip_tags,
445
453
  RTEST(rb_block) ? &autolink_callback : NULL,
454
+ rb_enc_get_index(rb_text),
446
455
  (void*)rb_block);
447
456
 
448
457
  if (count == 0)
@@ -465,4 +474,3 @@ void RUBY_EXPORT Init_rinku()
465
474
  rb_define_method(rb_mRinku, "auto_link", rb_rinku_autolink, -1);
466
475
  rb_define_const(rb_mRinku, "AUTOLINK_SHORT_DOMAINS", INT2FIX(SD_AUTOLINK_SHORT_DOMAINS));
467
476
  }
468
-
data/lib/rinku.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Rinku
2
- VERSION = "1.7.0"
2
+ VERSION = "1.7.2"
3
3
  attr_accessor :skip_tags
4
4
  extend self
5
5
  end
data/rinku.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'zendesk-rinku'
5
- s.version = '1.7.0'
5
+ s.version = '1.7.2.1'
6
6
  s.summary = "Mostly autolinking"
7
7
  s.description = <<-EOF
8
8
  A fast and very smart autolinking library that
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
12
12
  EOF
13
13
  s.email = 'shajith@zendesk.com'
14
14
  s.homepage = 'http://github.com/shajith/rinku'
15
- s.authors = ["Shajith Chacko", "Vicent Marti"]
15
+ s.authors = ["Vicent Marti", "Shajith Chacko"]
16
16
  # = MANIFEST =
17
17
  s.files = %w[
18
18
  COPYING
@@ -15,6 +15,10 @@ class RedcarpetAutolinkTest < Test::Unit::TestCase
15
15
  assert_equal expected, Rinku.auto_link(url)
16
16
  end
17
17
 
18
+ def test_segfault
19
+ Rinku.auto_link("a+b@d.com+e@f.com", mode=:all)
20
+ end
21
+
18
22
  def test_escapes_quotes
19
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>),
20
24
  %(http://website.com/"onmouseover=document.body.style.backgroundColor="pink";//)
@@ -32,7 +36,7 @@ class RedcarpetAutolinkTest < Test::Unit::TestCase
32
36
  Rinku.skip_tags = nil
33
37
  assert_not_equal Rinku.auto_link(url), url
34
38
  end
35
-
39
+
36
40
  def test_auto_link_with_single_trailing_punctuation_and_space
37
41
  url = "http://www.youtube.com"
38
42
  url_result = generate_result(url)
@@ -138,7 +142,7 @@ This is just a test. <a href="http://www.pokemon.com">http://www.pokemon.com</a>
138
142
  url2 = "http://www.ruby-doc.org/core/Bar.html"
139
143
 
140
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>")
141
- end
145
+ end
142
146
 
143
147
  def test_block
144
148
  link = Rinku.auto_link("Find ur favorite pokeman @ http://www.pokemon.com") do |url|
@@ -149,6 +153,12 @@ This is just a test. <a href="http://www.pokemon.com">http://www.pokemon.com</a>
149
153
  assert_equal link, "Find ur favorite pokeman @ <a href=\"http://www.pokemon.com\">POKEMAN WEBSITE</a>"
150
154
  end
151
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
+
152
162
  def test_autolink_works
153
163
  url = "http://example.com/"
154
164
  assert_linked "<a href=\"#{url}\">#{url}</a>", url
@@ -285,6 +295,19 @@ This is just a test. <a href="http://www.pokemon.com">http://www.pokemon.com</a>
285
295
  ret = Rinku.auto_link str
286
296
  assert_equal str.encoding, ret.encoding
287
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
+
288
311
  end
289
312
 
290
313
  def generate_result(link_text, href = nil)
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zendesk-rinku
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.7.2.1
5
5
  platform: ruby
6
6
  authors:
7
- - Shajith Chacko
8
7
  - Vicent Marti
8
+ - Shajith Chacko
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-31 00:00:00.000000000 Z
12
+ date: 2014-04-01 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! " A fast and very smart autolinking library that\n acts as a
15
15
  drop-in replacement for Rails `auto_link`\n\n This is just a fork of vmg's lib