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 +4 -4
- data/ext/rinku/autolink.c +14 -16
- data/ext/rinku/utf8.c +43 -1
- data/ext/rinku/utf8.h +3 -0
- data/lib/rinku.rb +1 -1
- data/rinku.gemspec +1 -1
- data/test/autolink_test.rb +18 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: efae79dff80a684e71b33c625f2335fe4867302d
|
4
|
+
data.tar.gz: 4b8daa1d4afe0d14a46003eb2a9e71248a283b9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b01768b18a0eda0cb7c2863af5fd150dbe121d4d349350fab023a29955b275dc7f2026ad3bdd69f28e688f0bc5581884c8c9d668ff3782360784779bbeeb916
|
7
|
+
data.tar.gz: aed5796d6929e1ee7fe111d6ff618cb216071c9fde4fa655a6a14ad1c14ccb0d5e7695e92ea9a1eb4cb917161e58fbe8b26832b69e1bf53211dd06a761d74308
|
data/ext/rinku/autolink.c
CHANGED
@@ -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
|
-
|
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
|
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
|
-
|
120
|
+
int32_t c = utf8proc_next(data, &i);
|
121
|
+
if (c == copen)
|
128
122
|
opening++;
|
129
|
-
else if (
|
123
|
+
else if (c == cclose)
|
130
124
|
closing++;
|
131
|
-
|
132
|
-
i++;
|
133
125
|
}
|
134
126
|
|
135
|
-
if (
|
136
|
-
|
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;
|
data/ext/rinku/utf8.c
CHANGED
@@ -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] &
|
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 ||
|
data/ext/rinku/utf8.h
CHANGED
@@ -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
|
|
data/lib/rinku.rb
CHANGED
data/rinku.gemspec
CHANGED
data/test/autolink_test.rb
CHANGED
@@ -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.
|
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:
|
11
|
+
date: 2017-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|