rinku 2.0.2 → 2.0.3

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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2982203836f1449fe5344a32f7ab1782f3cb4cc7
4
- data.tar.gz: 8461bfe12528f128cba4e81e9fb8f64e9903e6e5
3
+ metadata.gz: efae79dff80a684e71b33c625f2335fe4867302d
4
+ data.tar.gz: 4b8daa1d4afe0d14a46003eb2a9e71248a283b9b
5
5
  SHA512:
6
- metadata.gz: 3587f9e83406d7829cdbec671980536803f3b9e0ed87e6daf8e21389dad8d2cc521d49527b602e3ccaa7e40f3c41ef365ba4bbb42a0b69d6ed7c412bbdd914f3
7
- data.tar.gz: 68aa755836af8269edc44bcd4ae8134abe6a3bd7836140218f4bd618069f22ad16ff78c6814610f2525ca5f64cfac8657e2021c0ee238e1ba5d319e6efeb728c
6
+ metadata.gz: 0b01768b18a0eda0cb7c2863af5fd150dbe121d4d349350fab023a29955b275dc7f2026ad3bdd69f28e688f0bc5581884c8c9d668ff3782360784779bbeeb916
7
+ data.tar.gz: aed5796d6929e1ee7fe111d6ff618cb216071c9fde4fa655a6a14ad1c14ccb0d5e7695e92ea9a1eb4cb917161e58fbe8b26832b69e1bf53211dd06a761d74308
@@ -52,7 +52,7 @@ autolink_issafe(const uint8_t *link, size_t link_len)
52
52
  static bool
53
53
  autolink_delim(const uint8_t *data, struct autolink_pos *link)
54
54
  {
55
- uint8_t cclose, copen = 0;
55
+ int32_t cclose, copen = 0;
56
56
  size_t i;
57
57
 
58
58
  for (i = link->start; i < link->end; ++i)
@@ -88,15 +88,8 @@ autolink_delim(const uint8_t *data, struct autolink_pos *link)
88
88
  if (link->end == link->start)
89
89
  return false;
90
90
 
91
- cclose = data[link->end - 1];
92
-
93
- switch (cclose) {
94
- case '"': copen = '"'; break;
95
- case '\'': copen = '\''; break;
96
- case ')': copen = '('; break;
97
- case ']': copen = '['; break;
98
- case '}': copen = '{'; break;
99
- }
91
+ cclose = utf8proc_rewind(data, link->end);
92
+ copen = utf8proc_open_paren_character(cclose);
100
93
 
101
94
  if (copen != 0) {
102
95
  /* Try to close the final punctuation sign in this link; if
@@ -124,16 +117,21 @@ autolink_delim(const uint8_t *data, struct autolink_pos *link)
124
117
  size_t i = link->start;
125
118
 
126
119
  while (i < link->end) {
127
- if (data[i] == copen)
120
+ int32_t c = utf8proc_next(data, &i);
121
+ if (c == copen)
128
122
  opening++;
129
- else if (data[i] == cclose)
123
+ else if (c == cclose)
130
124
  closing++;
131
-
132
- i++;
133
125
  }
134
126
 
135
- if (closing > opening)
136
- link->end--;
127
+ if (copen == cclose) {
128
+ if (opening > 0)
129
+ utf8proc_back(data, &link->end);
130
+ }
131
+ else {
132
+ if (closing > opening)
133
+ utf8proc_back(data, &link->end);
134
+ }
137
135
  }
138
136
 
139
137
  return true;
@@ -75,6 +75,30 @@ int32_t utf8proc_next(const uint8_t *str, size_t *pos)
75
75
  return read_cp(str + p, length);
76
76
  }
77
77
 
78
+ int32_t utf8proc_back(const uint8_t *str, size_t *pos)
79
+ {
80
+ const size_t p = *pos;
81
+ int8_t length = 0;
82
+
83
+ if (!p)
84
+ return 0x0;
85
+
86
+ if ((str[p - 1] & 0x80) == 0x0) {
87
+ (*pos) -= 1;
88
+ return str[p - 1];
89
+ }
90
+
91
+ if (p > 1 && utf8proc_utf8class[str[p - 2]] == 2)
92
+ length = 2;
93
+ else if (p > 2 && utf8proc_utf8class[str[p - 3]] == 3)
94
+ length = 3;
95
+ else if (p > 3 && utf8proc_utf8class[str[p - 4]] == 4)
96
+ length = 4;
97
+
98
+ (*pos) -= length;
99
+ return read_cp(&str[*pos], length);
100
+ }
101
+
78
102
  size_t utf8proc_find_space(const uint8_t *str, size_t pos, size_t size)
79
103
  {
80
104
  while (pos < size) {
@@ -93,7 +117,7 @@ int32_t utf8proc_rewind(const uint8_t *data, size_t pos)
93
117
  if (!pos)
94
118
  return 0x0;
95
119
 
96
- if ((data[pos - 1] & 0xC0) == 0x0)
120
+ if ((data[pos - 1] & 0x80) == 0x0)
97
121
  return data[pos - 1];
98
122
 
99
123
  if (pos > 1 && utf8proc_utf8class[data[pos - 2]] == 2)
@@ -106,6 +130,24 @@ int32_t utf8proc_rewind(const uint8_t *data, size_t pos)
106
130
  return read_cp(&data[pos - length], length);
107
131
  }
108
132
 
133
+ int32_t utf8proc_open_paren_character(int32_t cclose)
134
+ {
135
+ switch (cclose) {
136
+ case '"': return '"';
137
+ case '\'': return '\'';
138
+ case ')': return '(';
139
+ case ']': return '[';
140
+ case '}': return '{';
141
+ case 65289: return 65288; /* () */
142
+ case 12305: return 12304; /* 【】 */
143
+ case 12303: return 12302; /* 『』 */
144
+ case 12301: return 12300; /* 「」 */
145
+ case 12299: return 12298; /* 《》 */
146
+ case 12297: return 12296; /* 〈〉 */
147
+ }
148
+ return 0;
149
+ }
150
+
109
151
  bool utf8proc_is_space(int32_t uc)
110
152
  {
111
153
  return (uc == 9 || uc == 10 || uc == 12 || uc == 13 ||
@@ -26,8 +26,11 @@ bool rinku_isalpha(char c);
26
26
  bool rinku_isalnum(char c);
27
27
 
28
28
  int32_t utf8proc_rewind(const uint8_t *data, size_t pos);
29
+ int32_t utf8proc_next(const uint8_t *str, size_t *pos);
30
+ int32_t utf8proc_back(const uint8_t *data, size_t *pos);
29
31
  size_t utf8proc_find_space(const uint8_t *str, size_t pos, size_t size);
30
32
 
33
+ int32_t utf8proc_open_paren_character(int32_t cclose);
31
34
  bool utf8proc_is_space(int32_t uc);
32
35
  bool utf8proc_is_punctuation(int32_t uc);
33
36
 
@@ -1,5 +1,5 @@
1
1
  module Rinku
2
- VERSION = "2.0.2"
2
+ VERSION = "2.0.3"
3
3
 
4
4
  class << self
5
5
  attr_accessor :skip_tags
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'rinku'
3
- s.version = '2.0.2'
3
+ s.version = '2.0.3'
4
4
  s.summary = "Mostly autolinking"
5
5
  s.description = <<-EOF
6
6
  A fast and very smart autolinking library that
@@ -412,4 +412,22 @@ This is just a test. <a href="http://www.pokemon.com">http://www.pokemon.com</a>
412
412
  assert_linked "URL is #{generate_result(url, "mailto:#{url}")}.", "URL is #{url}."
413
413
  assert_linked "(URL is #{generate_result(url, "mailto:#{url}")}.)", "(URL is #{url}.)"
414
414
  end
415
+
416
+ def test_urls_with_parens
417
+ assert_linked "(<a href=\"http://example.com\">http://example.com</a>)", "(http://example.com)"
418
+ assert_linked "((<a href=\"http://example.com/()\">http://example.com/()</a>))", "((http://example.com/()))"
419
+ assert_linked "[<a href=\"http://example.com/()\">http://example.com/()</a>]", "[http://example.com/()]"
420
+
421
+ assert_linked "(<a href=\"http://example.com/\">http://example.com/</a>)", "(http://example.com/)"
422
+ assert_linked "【<a href=\"http://example.com/\">http://example.com/</a>】", "【http://example.com/】"
423
+ assert_linked "『<a href=\"http://example.com/\">http://example.com/</a>』", "『http://example.com/』"
424
+ assert_linked "「<a href=\"http://example.com/\">http://example.com/</a>」", "「http://example.com/」"
425
+ assert_linked "《<a href=\"http://example.com/\">http://example.com/</a>》", "《http://example.com/》"
426
+ assert_linked "〈<a href=\"http://example.com/\">http://example.com/</a>〉", "〈http://example.com/〉"
427
+ end
428
+
429
+ def test_urls_with_quotes
430
+ assert_linked "'<a href=\"http://example.com\">http://example.com</a>'", "'http://example.com'"
431
+ assert_linked "\"<a href=\"http://example.com\">http://example.com</a>\"\"", "\"http://example.com\"\""
432
+ end
415
433
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rinku
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vicent Marti
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-07 00:00:00.000000000 Z
11
+ date: 2017-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake