twitter-text 1.14.7 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rspec +1 -1
- data/README.md +104 -33
- data/lib/assets/tld_lib.yml +1 -0
- data/lib/twitter-text.rb +2 -0
- data/lib/twitter-text/autolink.rb +4 -4
- data/lib/twitter-text/configuration.rb +53 -0
- data/lib/twitter-text/deprecation.rb +1 -1
- data/lib/twitter-text/extractor.rb +31 -1
- data/lib/twitter-text/regex.rb +13 -13
- data/lib/twitter-text/validation.rb +155 -43
- data/lib/twitter-text/weighted_range.rb +18 -0
- data/spec/autolinking_spec.rb +161 -161
- data/spec/configuration_spec.rb +91 -0
- data/spec/extractor_spec.rb +92 -72
- data/spec/hithighlighter_spec.rb +15 -15
- data/spec/regex_spec.rb +7 -7
- data/spec/rewriter_spec.rb +110 -109
- data/spec/spec_helper.rb +13 -15
- data/spec/test_urls.rb +6 -4
- data/spec/twitter_text_spec.rb +2 -2
- data/spec/unicode_spec.rb +10 -10
- data/spec/validation_spec.rb +35 -11
- data/test/conformance_test.rb +14 -0
- data/twitter-text.gemspec +11 -9
- metadata +53 -32
- data/lib/assets/tld_lib.yml +0 -1565
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module Twitter
|
4
|
+
class WeightedRange
|
5
|
+
attr_reader :start, :end, :weight
|
6
|
+
|
7
|
+
def initialize(range = {})
|
8
|
+
raise ArgumentError.new("Invalid range") unless [:start, :end, :weight].all? { |key| range.key?(key) && range[key].is_a?(Integer) }
|
9
|
+
@start = range[:start]
|
10
|
+
@end = range[:end]
|
11
|
+
@weight = range[:weight]
|
12
|
+
end
|
13
|
+
|
14
|
+
def contains?(code_point)
|
15
|
+
code_point >= @start && code_point <= @end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/spec/autolinking_spec.rb
CHANGED
@@ -19,7 +19,7 @@ describe Twitter::Autolink do
|
|
19
19
|
def original_text; "hello @jacob"; end
|
20
20
|
|
21
21
|
it "should be linked" do
|
22
|
-
@autolinked_text.
|
22
|
+
expect(@autolinked_text).to link_to_screen_name('jacob')
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -27,7 +27,7 @@ describe Twitter::Autolink do
|
|
27
27
|
def original_text() "@jaCob iS cOoL" end
|
28
28
|
|
29
29
|
it "should be linked" do
|
30
|
-
@autolinked_text.
|
30
|
+
expect(@autolinked_text).to link_to_screen_name('jaCob')
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -35,7 +35,7 @@ describe Twitter::Autolink do
|
|
35
35
|
def original_text; "@jacob you're cool"; end
|
36
36
|
|
37
37
|
it "should be linked" do
|
38
|
-
@autolinked_text.
|
38
|
+
expect(@autolinked_text).to link_to_screen_name('jacob')
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -43,7 +43,7 @@ describe Twitter::Autolink do
|
|
43
43
|
def original_text; "meet@the beach"; end
|
44
44
|
|
45
45
|
it "should not be linked" do
|
46
|
-
Nokogiri::HTML(@autolinked_text).search('a').
|
46
|
+
expect(Nokogiri::HTML(@autolinked_text).search('a')).to be_empty
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
@@ -51,7 +51,7 @@ describe Twitter::Autolink do
|
|
51
51
|
def original_text; "great.@jacob"; end
|
52
52
|
|
53
53
|
it "should be linked" do
|
54
|
-
@autolinked_text.
|
54
|
+
expect(@autolinked_text).to link_to_screen_name('jacob')
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -59,7 +59,7 @@ describe Twitter::Autolink do
|
|
59
59
|
def original_text; "@zach&^$%^"; end
|
60
60
|
|
61
61
|
it "should not be linked" do
|
62
|
-
@autolinked_text.
|
62
|
+
expect(@autolinked_text).to link_to_screen_name('zach')
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
@@ -70,7 +70,7 @@ describe Twitter::Autolink do
|
|
70
70
|
end
|
71
71
|
|
72
72
|
it "should not be linked" do
|
73
|
-
@autolinked_text.
|
73
|
+
expect(@autolinked_text).to link_to_screen_name(@twenty_character_username)
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
@@ -78,7 +78,7 @@ describe Twitter::Autolink do
|
|
78
78
|
def original_text; "@jacobの"; end
|
79
79
|
|
80
80
|
it "should be linked" do
|
81
|
-
@autolinked_text.
|
81
|
+
expect(@autolinked_text).to link_to_screen_name('jacob')
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
@@ -86,7 +86,7 @@ describe Twitter::Autolink do
|
|
86
86
|
def original_text; "あ@matz"; end
|
87
87
|
|
88
88
|
it "should be linked" do
|
89
|
-
@autolinked_text.
|
89
|
+
expect(@autolinked_text).to link_to_screen_name('matz')
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
@@ -94,7 +94,7 @@ describe Twitter::Autolink do
|
|
94
94
|
def original_text; "あ@yoshimiの"; end
|
95
95
|
|
96
96
|
it "should be linked" do
|
97
|
-
@autolinked_text.
|
97
|
+
expect(@autolinked_text).to link_to_screen_name('yoshimi')
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
@@ -104,7 +104,7 @@ describe Twitter::Autolink do
|
|
104
104
|
end
|
105
105
|
|
106
106
|
it "should be linked" do
|
107
|
-
@autolinked_text.
|
107
|
+
expect(@autolinked_text).to link_to_screen_name('jacob')
|
108
108
|
end
|
109
109
|
end
|
110
110
|
end
|
@@ -114,8 +114,8 @@ describe Twitter::Autolink do
|
|
114
114
|
context "when List is not available" do
|
115
115
|
it "should not be linked" do
|
116
116
|
@autolinked_text = TestAutolink.new.auto_link_usernames_or_lists("hello @jacob/my-list", :suppress_lists => true)
|
117
|
-
@autolinked_text.
|
118
|
-
@autolinked_text.
|
117
|
+
expect(@autolinked_text).to_not link_to_list_path('jacob/my-list')
|
118
|
+
expect(@autolinked_text).to include('my-list')
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
@@ -123,7 +123,7 @@ describe Twitter::Autolink do
|
|
123
123
|
def original_text; "hello @jacob/my-list"; end
|
124
124
|
|
125
125
|
it "should be linked" do
|
126
|
-
@autolinked_text.
|
126
|
+
expect(@autolinked_text).to link_to_list_path('jacob/my-list')
|
127
127
|
end
|
128
128
|
end
|
129
129
|
|
@@ -131,8 +131,8 @@ describe Twitter::Autolink do
|
|
131
131
|
def original_text; "hello @jacob/ my-list"; end
|
132
132
|
|
133
133
|
it "should NOT be linked" do
|
134
|
-
@autolinked_text.
|
135
|
-
@autolinked_text.
|
134
|
+
expect(@autolinked_text).to_not link_to_list_path('jacob/my-list')
|
135
|
+
expect(@autolinked_text).to link_to_screen_name('jacob')
|
136
136
|
end
|
137
137
|
end
|
138
138
|
|
@@ -140,7 +140,7 @@ describe Twitter::Autolink do
|
|
140
140
|
def original_text; "hello @/my-list"; end
|
141
141
|
|
142
142
|
it "should NOT be linked" do
|
143
|
-
Nokogiri::HTML(@autolinked_text).search('a').
|
143
|
+
expect(Nokogiri::HTML(@autolinked_text).search('a')).to be_empty
|
144
144
|
end
|
145
145
|
end
|
146
146
|
|
@@ -148,7 +148,7 @@ describe Twitter::Autolink do
|
|
148
148
|
def original_text; "@jacob/my-list"; end
|
149
149
|
|
150
150
|
it "should be linked" do
|
151
|
-
@autolinked_text.
|
151
|
+
expect(@autolinked_text).to link_to_list_path('jacob/my-list')
|
152
152
|
end
|
153
153
|
end
|
154
154
|
|
@@ -156,7 +156,7 @@ describe Twitter::Autolink do
|
|
156
156
|
def original_text; "meet@the/beach"; end
|
157
157
|
|
158
158
|
it "should not be linked" do
|
159
|
-
Nokogiri::HTML(@autolinked_text).search('a').
|
159
|
+
expect(Nokogiri::HTML(@autolinked_text).search('a')).to be_empty
|
160
160
|
end
|
161
161
|
end
|
162
162
|
|
@@ -165,7 +165,7 @@ describe Twitter::Autolink do
|
|
165
165
|
|
166
166
|
it "should be linked" do
|
167
167
|
@autolinked_text = TestAutolink.new.auto_link("great.@jacob/my-list")
|
168
|
-
@autolinked_text.
|
168
|
+
expect(@autolinked_text).to link_to_list_path('jacob/my-list')
|
169
169
|
end
|
170
170
|
end
|
171
171
|
|
@@ -173,7 +173,7 @@ describe Twitter::Autolink do
|
|
173
173
|
def original_text; "@zach/test&^$%^"; end
|
174
174
|
|
175
175
|
it "should be linked" do
|
176
|
-
@autolinked_text.
|
176
|
+
expect(@autolinked_text).to link_to_list_path('zach/test')
|
177
177
|
end
|
178
178
|
end
|
179
179
|
|
@@ -184,7 +184,7 @@ describe Twitter::Autolink do
|
|
184
184
|
end
|
185
185
|
|
186
186
|
it "should be linked" do
|
187
|
-
@autolinked_text.
|
187
|
+
expect(@autolinked_text).to link_to_list_path(@twentyfive_character_list)
|
188
188
|
end
|
189
189
|
end
|
190
190
|
end
|
@@ -194,7 +194,7 @@ describe Twitter::Autolink do
|
|
194
194
|
def original_text; "#123"; end
|
195
195
|
|
196
196
|
it "should not be linked" do
|
197
|
-
@autolinked_text.
|
197
|
+
expect(@autolinked_text).to_not have_autolinked_hashtag('#123')
|
198
198
|
end
|
199
199
|
end
|
200
200
|
|
@@ -202,7 +202,7 @@ describe Twitter::Autolink do
|
|
202
202
|
def original_text; "#ab1d"; end
|
203
203
|
|
204
204
|
it "should be linked" do
|
205
|
-
@autolinked_text.
|
205
|
+
expect(@autolinked_text).to have_autolinked_hashtag('#ab1d')
|
206
206
|
end
|
207
207
|
end
|
208
208
|
|
@@ -210,7 +210,7 @@ describe Twitter::Autolink do
|
|
210
210
|
def original_text; "#a_b_c_d"; end
|
211
211
|
|
212
212
|
it "should be linked" do
|
213
|
-
@autolinked_text.
|
213
|
+
expect(@autolinked_text).to have_autolinked_hashtag(original_text)
|
214
214
|
end
|
215
215
|
end
|
216
216
|
|
@@ -218,7 +218,7 @@ describe Twitter::Autolink do
|
|
218
218
|
def original_text; "ab#cd"; end
|
219
219
|
|
220
220
|
it "should not be linked" do
|
221
|
-
@autolinked_text.
|
221
|
+
expect(@autolinked_text).to_not have_autolinked_hashtag(original_text)
|
222
222
|
end
|
223
223
|
end
|
224
224
|
|
@@ -226,11 +226,11 @@ describe Twitter::Autolink do
|
|
226
226
|
def original_text; "Here's my url: http://foobar.com/#home"; end
|
227
227
|
|
228
228
|
it "should not link the hashtag" do
|
229
|
-
@autolinked_text.
|
229
|
+
expect(@autolinked_text).to_not have_autolinked_hashtag('#home')
|
230
230
|
end
|
231
231
|
|
232
232
|
it "should link the url" do
|
233
|
-
@autolinked_text.
|
233
|
+
expect(@autolinked_text).to have_autolinked_url('http://foobar.com/#home')
|
234
234
|
end
|
235
235
|
end
|
236
236
|
|
@@ -238,7 +238,7 @@ describe Twitter::Autolink do
|
|
238
238
|
def original_text; "#2ab"; end
|
239
239
|
|
240
240
|
it "should be linked" do
|
241
|
-
@autolinked_text.
|
241
|
+
expect(@autolinked_text).to have_autolinked_hashtag(original_text)
|
242
242
|
end
|
243
243
|
end
|
244
244
|
|
@@ -246,9 +246,9 @@ describe Twitter::Autolink do
|
|
246
246
|
def original_text; "I'm frickin' awesome #ab #cd #ef"; end
|
247
247
|
|
248
248
|
it "links each hashtag" do
|
249
|
-
@autolinked_text.
|
250
|
-
@autolinked_text.
|
251
|
-
@autolinked_text.
|
249
|
+
expect(@autolinked_text).to have_autolinked_hashtag('#ab')
|
250
|
+
expect(@autolinked_text).to have_autolinked_hashtag('#cd')
|
251
|
+
expect(@autolinked_text).to have_autolinked_hashtag('#ef')
|
252
252
|
end
|
253
253
|
end
|
254
254
|
|
@@ -256,7 +256,7 @@ describe Twitter::Autolink do
|
|
256
256
|
def original_text; "ok, great.#abc"; end
|
257
257
|
|
258
258
|
it "should be linked" do
|
259
|
-
@autolinked_text.
|
259
|
+
expect(@autolinked_text).to have_autolinked_hashtag('#abc')
|
260
260
|
end
|
261
261
|
end
|
262
262
|
|
@@ -264,7 +264,7 @@ describe Twitter::Autolink do
|
|
264
264
|
def original_text; "&#nbsp;"; end
|
265
265
|
|
266
266
|
it "should not be linked" do
|
267
|
-
@autolinked_text.
|
267
|
+
expect(@autolinked_text).to_not have_autolinked_hashtag('#nbsp;')
|
268
268
|
end
|
269
269
|
end
|
270
270
|
|
@@ -272,7 +272,7 @@ describe Twitter::Autolink do
|
|
272
272
|
def original_text; "#great!"; end
|
273
273
|
|
274
274
|
it "should be linked, but should not include the !" do
|
275
|
-
@autolinked_text.
|
275
|
+
expect(@autolinked_text).to have_autolinked_hashtag('#great')
|
276
276
|
end
|
277
277
|
end
|
278
278
|
|
@@ -280,7 +280,7 @@ describe Twitter::Autolink do
|
|
280
280
|
def original_text; "#twj_devの"; end
|
281
281
|
|
282
282
|
it "should be linked" do
|
283
|
-
@autolinked_text.
|
283
|
+
expect(@autolinked_text).to have_autolinked_hashtag('#twj_devの')
|
284
284
|
end
|
285
285
|
end
|
286
286
|
|
@@ -288,7 +288,7 @@ describe Twitter::Autolink do
|
|
288
288
|
def original_text; "#{[0x3000].pack('U')}#twj_dev"; end
|
289
289
|
|
290
290
|
it "should be linked" do
|
291
|
-
@autolinked_text.
|
291
|
+
expect(@autolinked_text).to have_autolinked_hashtag('#twj_dev')
|
292
292
|
end
|
293
293
|
end
|
294
294
|
|
@@ -296,7 +296,7 @@ describe Twitter::Autolink do
|
|
296
296
|
def original_text; "#twj_dev#{[0x3000].pack('U')}"; end
|
297
297
|
|
298
298
|
it "should be linked" do
|
299
|
-
@autolinked_text.
|
299
|
+
expect(@autolinked_text).to have_autolinked_hashtag('#twj_dev')
|
300
300
|
end
|
301
301
|
end
|
302
302
|
|
@@ -305,8 +305,8 @@ describe Twitter::Autolink do
|
|
305
305
|
|
306
306
|
it "should be linked" do
|
307
307
|
link = Nokogiri::HTML(@autolinked_text).search('a')
|
308
|
-
(link.inner_text.respond_to?(:force_encoding) ? link.inner_text.force_encoding("utf-8") : link.inner_text).
|
309
|
-
link.first['href'].
|
308
|
+
expect((link.inner_text.respond_to?(:force_encoding) ? link.inner_text.force_encoding("utf-8") : link.inner_text)).to be == "#{[0xFF03].pack('U')}twj_dev"
|
309
|
+
expect(link.first['href']).to be == 'https://twitter.com/search?q=%23twj_dev'
|
310
310
|
end
|
311
311
|
end
|
312
312
|
|
@@ -317,7 +317,7 @@ describe Twitter::Autolink do
|
|
317
317
|
end
|
318
318
|
|
319
319
|
it "should be linked" do
|
320
|
-
@autolinked_text.
|
320
|
+
expect(@autolinked_text).to be == "<a class=\"tweet-url hashtag\" href=\"https://twitter.com/search?q=%23éhashtag\" rel=\"nofollow\" title=\"#éhashtag\">#éhashtag</a>"
|
321
321
|
end
|
322
322
|
end
|
323
323
|
|
@@ -330,7 +330,7 @@ describe Twitter::Autolink do
|
|
330
330
|
def original_text; "On my search engine #{url} I found good links."; end
|
331
331
|
|
332
332
|
it "should be linked" do
|
333
|
-
@autolinked_text.
|
333
|
+
expect(@autolinked_text).to have_autolinked_url(url)
|
334
334
|
end
|
335
335
|
end
|
336
336
|
|
@@ -338,7 +338,7 @@ describe Twitter::Autolink do
|
|
338
338
|
def original_text; "いまなにしてる#{url}いまなにしてる"; end
|
339
339
|
|
340
340
|
it "should be linked" do
|
341
|
-
@autolinked_text.
|
341
|
+
expect(@autolinked_text).to have_autolinked_url(url)
|
342
342
|
end
|
343
343
|
end
|
344
344
|
|
@@ -346,14 +346,14 @@ describe Twitter::Autolink do
|
|
346
346
|
def original_text; "I found a neatness (#{url})"; end
|
347
347
|
|
348
348
|
it "should be linked" do
|
349
|
-
@autolinked_text.
|
349
|
+
expect(@autolinked_text).to have_autolinked_url(url)
|
350
350
|
end
|
351
351
|
|
352
352
|
context "when the URL ends with a slash;" do
|
353
353
|
def url; "http://www.google.com/"; end
|
354
354
|
|
355
355
|
it "should be linked" do
|
356
|
-
@autolinked_text.
|
356
|
+
expect(@autolinked_text).to have_autolinked_url(url)
|
357
357
|
end
|
358
358
|
end
|
359
359
|
|
@@ -361,7 +361,7 @@ describe Twitter::Autolink do
|
|
361
361
|
def url; "http://www.google.com/fsdfasdf"; end
|
362
362
|
|
363
363
|
it "should be linked" do
|
364
|
-
@autolinked_text.
|
364
|
+
expect(@autolinked_text).to have_autolinked_url(url)
|
365
365
|
end
|
366
366
|
end
|
367
367
|
end
|
@@ -370,14 +370,14 @@ describe Twitter::Autolink do
|
|
370
370
|
def original_text; "I found a neatness (#{url})"; end
|
371
371
|
|
372
372
|
it "should be linked" do
|
373
|
-
@autolinked_text.
|
373
|
+
expect(@autolinked_text).to have_autolinked_url(url)
|
374
374
|
end
|
375
375
|
|
376
376
|
context "wikipedia" do
|
377
377
|
def url; "http://en.wikipedia.org/wiki/Madonna_(artist)"; end
|
378
378
|
|
379
379
|
it "should be linked" do
|
380
|
-
@autolinked_text.
|
380
|
+
expect(@autolinked_text).to have_autolinked_url(url)
|
381
381
|
end
|
382
382
|
end
|
383
383
|
|
@@ -385,7 +385,7 @@ describe Twitter::Autolink do
|
|
385
385
|
def url; "http://msdn.com/S(deadbeef)/page.htm"; end
|
386
386
|
|
387
387
|
it "should be linked" do
|
388
|
-
@autolinked_text.
|
388
|
+
expect(@autolinked_text).to have_autolinked_url(url)
|
389
389
|
end
|
390
390
|
end
|
391
391
|
|
@@ -393,7 +393,7 @@ describe Twitter::Autolink do
|
|
393
393
|
def url; "http://example.com/i_has_a_("; end
|
394
394
|
|
395
395
|
it "should be linked" do
|
396
|
-
@autolinked_text.
|
396
|
+
expect(@autolinked_text).to have_autolinked_url("http://example.com/i_has_a_")
|
397
397
|
end
|
398
398
|
end
|
399
399
|
|
@@ -401,7 +401,7 @@ describe Twitter::Autolink do
|
|
401
401
|
def url; "http://foo.com/foo_(\")_bar" end
|
402
402
|
|
403
403
|
it "should be linked" do
|
404
|
-
@autolinked_text.
|
404
|
+
expect(@autolinked_text).to have_autolinked_url("http://foo.com/foo_")
|
405
405
|
end
|
406
406
|
end
|
407
407
|
|
@@ -409,7 +409,7 @@ describe Twitter::Autolink do
|
|
409
409
|
def url; 'http://x.xx.com/("style="color:red"onmouseover="alert(1)' end
|
410
410
|
|
411
411
|
it "should be linked" do
|
412
|
-
@autolinked_text.
|
412
|
+
expect(@autolinked_text).to have_autolinked_url("http://x.xx.com/")
|
413
413
|
end
|
414
414
|
end
|
415
415
|
end
|
@@ -418,7 +418,7 @@ describe Twitter::Autolink do
|
|
418
418
|
def original_text; "Check this out @hoverbird:#{url}"; end
|
419
419
|
|
420
420
|
it "should be linked" do
|
421
|
-
@autolinked_text.
|
421
|
+
expect(@autolinked_text).to have_autolinked_url(url)
|
422
422
|
end
|
423
423
|
end
|
424
424
|
|
@@ -426,7 +426,7 @@ describe Twitter::Autolink do
|
|
426
426
|
it "does not consume ending punctuation" do
|
427
427
|
matcher = TestAutolink.new
|
428
428
|
%w| ? ! , . : ; ] ) } = \ ' |.each do |char|
|
429
|
-
matcher.auto_link("#{url}#{char}").
|
429
|
+
expect(matcher.auto_link("#{url}#{char}")).to have_autolinked_url(url)
|
430
430
|
end
|
431
431
|
end
|
432
432
|
end
|
@@ -435,7 +435,7 @@ describe Twitter::Autolink do
|
|
435
435
|
it "should be linked" do
|
436
436
|
matcher = TestAutolink.new
|
437
437
|
%w| \ ' / ! = |.each do |char|
|
438
|
-
matcher.auto_link("#{char}#{url}").
|
438
|
+
expect(matcher.auto_link("#{char}#{url}")).to have_autolinked_url(url)
|
439
439
|
end
|
440
440
|
end
|
441
441
|
end
|
@@ -444,7 +444,7 @@ describe Twitter::Autolink do
|
|
444
444
|
def original_text; "<link rel='true'>#{url}</link>"; end
|
445
445
|
|
446
446
|
it "should be linked" do
|
447
|
-
@autolinked_text.
|
447
|
+
expect(@autolinked_text).to have_autolinked_url(url)
|
448
448
|
end
|
449
449
|
end
|
450
450
|
|
@@ -452,8 +452,8 @@ describe Twitter::Autolink do
|
|
452
452
|
def original_text; "http://www.links.org link at start of page, link at end http://www.foo.org"; end
|
453
453
|
|
454
454
|
it "should autolink each one" do
|
455
|
-
@autolinked_text.
|
456
|
-
@autolinked_text.
|
455
|
+
expect(@autolinked_text).to have_autolinked_url('http://www.links.org')
|
456
|
+
expect(@autolinked_text).to have_autolinked_url('http://www.foo.org')
|
457
457
|
end
|
458
458
|
end
|
459
459
|
|
@@ -461,9 +461,9 @@ describe Twitter::Autolink do
|
|
461
461
|
def original_text; "http://foo.com https://bar.com http://mail.foobar.org"; end
|
462
462
|
|
463
463
|
it "should autolink each one, in the proper order" do
|
464
|
-
@autolinked_text.
|
465
|
-
@autolinked_text.
|
466
|
-
@autolinked_text.
|
464
|
+
expect(@autolinked_text).to have_autolinked_url('http://foo.com')
|
465
|
+
expect(@autolinked_text).to have_autolinked_url('https://bar.com')
|
466
|
+
expect(@autolinked_text).to have_autolinked_url('http://mail.foobar.org')
|
467
467
|
end
|
468
468
|
end
|
469
469
|
|
@@ -471,7 +471,7 @@ describe Twitter::Autolink do
|
|
471
471
|
def original_text; "Yahoo integriert Facebook http://golem.mobi/0912/71607.html"; end
|
472
472
|
|
473
473
|
it "should autolink it" do
|
474
|
-
@autolinked_text.
|
474
|
+
expect(@autolinked_text).to have_autolinked_url('http://golem.mobi/0912/71607.html')
|
475
475
|
end
|
476
476
|
end
|
477
477
|
|
@@ -480,7 +480,7 @@ describe Twitter::Autolink do
|
|
480
480
|
|
481
481
|
it "does not link at all" do
|
482
482
|
link = Nokogiri::HTML(@autolinked_text).search('a')
|
483
|
-
link.
|
483
|
+
expect(link).to be_empty
|
484
484
|
end
|
485
485
|
end
|
486
486
|
|
@@ -489,7 +489,7 @@ describe Twitter::Autolink do
|
|
489
489
|
def original_text; 'http://x.xx.com/@"style="color:pink"onmouseover=alert(1)//'; end
|
490
490
|
|
491
491
|
it "should not allow XSS follwing @" do
|
492
|
-
@autolinked_text.
|
492
|
+
expect(@autolinked_text).to have_autolinked_url('http://x.xx.com/')
|
493
493
|
end
|
494
494
|
end
|
495
495
|
|
@@ -497,7 +497,7 @@ describe Twitter::Autolink do
|
|
497
497
|
def original_text; 'http://example.com/@foobar'; end
|
498
498
|
|
499
499
|
it "should link url" do
|
500
|
-
@autolinked_text.
|
500
|
+
expect(@autolinked_text).to have_autolinked_url('http://example.com/@foobar')
|
501
501
|
end
|
502
502
|
end
|
503
503
|
|
@@ -505,8 +505,8 @@ describe Twitter::Autolink do
|
|
505
505
|
def original_text; 'http://example.com/@foobar/'; end
|
506
506
|
|
507
507
|
it "should not link the username but link full url" do
|
508
|
-
@autolinked_text.
|
509
|
-
@autolinked_text.
|
508
|
+
expect(@autolinked_text).to have_autolinked_url('http://example.com/@foobar/')
|
509
|
+
expect(@autolinked_text).to_not link_to_screen_name('foobar')
|
510
510
|
end
|
511
511
|
end
|
512
512
|
end
|
@@ -516,7 +516,7 @@ describe Twitter::Autolink do
|
|
516
516
|
def original_text; "Test a ton of periods http://example.com/path.........................................."; end
|
517
517
|
|
518
518
|
it "should autolink" do
|
519
|
-
@autolinked_text.
|
519
|
+
expect(@autolinked_text).to have_autolinked_url('http://example.com/path')
|
520
520
|
end
|
521
521
|
end
|
522
522
|
|
@@ -524,7 +524,7 @@ describe Twitter::Autolink do
|
|
524
524
|
def original_text; "Single char file ext http://www.bestbuy.com/site/Currie+Technologies+-+Ezip+400+Scooter/9885188.p?id=1218189013070&skuId=9885188"; end
|
525
525
|
|
526
526
|
it "should autolink" do
|
527
|
-
@autolinked_text.
|
527
|
+
expect(@autolinked_text).to have_autolinked_url('http://www.bestbuy.com/site/Currie+Technologies+-+Ezip+400+Scooter/9885188.p?id=1218189013070&skuId=9885188')
|
528
528
|
end
|
529
529
|
end
|
530
530
|
end
|
@@ -538,21 +538,21 @@ describe Twitter::Autolink do
|
|
538
538
|
|
539
539
|
it "should allow url/hashtag overlap" do
|
540
540
|
auto_linked = @linker.auto_link("https://twitter.com/#search")
|
541
|
-
auto_linked.
|
541
|
+
expect(auto_linked).to have_autolinked_url('https://twitter.com/#search')
|
542
542
|
end
|
543
543
|
|
544
544
|
it "should not add invalid option in HTML tags" do
|
545
545
|
auto_linked = @linker.auto_link("https://twitter.com/ is a URL, not a hashtag", :hashtag_class => 'hashtag_classname')
|
546
|
-
auto_linked.
|
547
|
-
auto_linked.
|
548
|
-
auto_linked.
|
546
|
+
expect(auto_linked).to have_autolinked_url('https://twitter.com/')
|
547
|
+
expect(auto_linked).to_not include('hashtag_class')
|
548
|
+
expect(auto_linked).to_not include('hashtag_classname')
|
549
549
|
end
|
550
550
|
|
551
551
|
it "should autolink url/hashtag/mention in text with Unicode supplementary characters" do
|
552
552
|
auto_linked = @linker.auto_link("#{[0x10400].pack('U')} #hashtag #{[0x10400].pack('U')} @mention #{[0x10400].pack('U')} http://twitter.com/")
|
553
|
-
auto_linked.
|
554
|
-
auto_linked.
|
555
|
-
auto_linked.
|
553
|
+
expect(auto_linked).to have_autolinked_hashtag('#hashtag')
|
554
|
+
expect(auto_linked).to link_to_screen_name('mention')
|
555
|
+
expect(auto_linked).to have_autolinked_url('http://twitter.com/')
|
556
556
|
end
|
557
557
|
end
|
558
558
|
|
@@ -574,11 +574,11 @@ describe Twitter::Autolink do
|
|
574
574
|
]
|
575
575
|
}])
|
576
576
|
html = Nokogiri::HTML(linked)
|
577
|
-
html.search('a').
|
578
|
-
html.search('a[@href="http://t.co/0JG5Mcq"]').
|
579
|
-
html.search('span[@class=js-display-url]').inner_text.
|
580
|
-
html.inner_text.
|
581
|
-
html.search('span[@style="position:absolute;left:-9999px;"]').size.
|
577
|
+
expect(html.search('a')).to_not be_empty
|
578
|
+
expect(html.search('a[@href="http://t.co/0JG5Mcq"]')).to_not be_empty
|
579
|
+
expect(html.search('span[@class=js-display-url]').inner_text).to be == "blog.twitter.com/2011/05/twitte"
|
580
|
+
expect(html.inner_text).to be == " http://blog.twitter.com/2011/05/twitter-for-mac-update.html …"
|
581
|
+
expect(html.search('span[@style="position:absolute;left:-9999px;"]').size).to be == 4
|
582
582
|
end
|
583
583
|
|
584
584
|
it "should accept invisible_tag_attrs option" do
|
@@ -596,7 +596,7 @@ describe Twitter::Autolink do
|
|
596
596
|
:invisible_tag_attrs => "style='dummy;'"
|
597
597
|
})
|
598
598
|
html = Nokogiri::HTML(linked)
|
599
|
-
html.search('span[@style="dummy;"]').size.
|
599
|
+
expect(html.search('span[@style="dummy;"]').size).to be == 4
|
600
600
|
end
|
601
601
|
|
602
602
|
it "should show display_url if available in entity" do
|
@@ -609,90 +609,90 @@ describe Twitter::Autolink do
|
|
609
609
|
}]
|
610
610
|
)
|
611
611
|
html = Nokogiri::HTML(linked)
|
612
|
-
html.search('a').
|
613
|
-
html.search('a[@href="http://t.co/0JG5Mcq"]').
|
614
|
-
html.search('span[@class=js-display-url]').inner_text.
|
615
|
-
html.inner_text.
|
612
|
+
expect(html.search('a')).to_not be_empty
|
613
|
+
expect(html.search('a[@href="http://t.co/0JG5Mcq"]')).to_not be_empty
|
614
|
+
expect(html.search('span[@class=js-display-url]').inner_text).to be == "blog.twitter.com/2011/05/twitte"
|
615
|
+
expect(html.inner_text).to be == " http://blog.twitter.com/2011/05/twitter-for-mac-update.html …"
|
616
616
|
end
|
617
617
|
|
618
618
|
it "should apply :class as a CSS class" do
|
619
619
|
linked = @linker.auto_link("http://example.com/", :class => 'myclass')
|
620
|
-
linked.
|
621
|
-
linked.
|
620
|
+
expect(linked).to have_autolinked_url('http://example.com/')
|
621
|
+
expect(linked).to match(/myclass/)
|
622
622
|
end
|
623
623
|
|
624
624
|
it "should apply :url_class only on URL" do
|
625
625
|
linked = @linker.auto_link("http://twitter.com")
|
626
|
-
linked.
|
627
|
-
linked.
|
626
|
+
expect(linked).to have_autolinked_url('http://twitter.com')
|
627
|
+
expect(expect(linked)).to_not match(/class/)
|
628
628
|
|
629
629
|
linked = @linker.auto_link("http://twitter.com", :url_class => 'testClass')
|
630
|
-
linked.
|
631
|
-
linked.
|
630
|
+
expect(linked).to have_autolinked_url('http://twitter.com')
|
631
|
+
expect(linked).to match(/class=\"testClass\"/)
|
632
632
|
|
633
633
|
linked = @linker.auto_link("#hash @tw", :url_class => 'testClass')
|
634
|
-
linked.
|
635
|
-
linked.
|
636
|
-
linked.
|
634
|
+
expect(linked).to match(/class=\"tweet-url hashtag\"/)
|
635
|
+
expect(linked).to match(/class=\"tweet-url username\"/)
|
636
|
+
expect(linked).to_not match(/class=\"testClass\"/)
|
637
637
|
end
|
638
638
|
|
639
639
|
it "should add rel=nofollow by default" do
|
640
640
|
linked = @linker.auto_link("http://example.com/")
|
641
|
-
linked.
|
642
|
-
linked.
|
641
|
+
expect(linked).to have_autolinked_url('http://example.com/')
|
642
|
+
expect(linked).to match(/nofollow/)
|
643
643
|
end
|
644
644
|
|
645
645
|
it "should include the '@' symbol in a username when passed :username_include_symbol" do
|
646
646
|
linked = @linker.auto_link("@user", :username_include_symbol => true)
|
647
|
-
linked.
|
647
|
+
expect(linked).to link_to_screen_name('user', '@user')
|
648
648
|
end
|
649
649
|
|
650
650
|
it "should include the '@' symbol in a list when passed :username_include_symbol" do
|
651
651
|
linked = @linker.auto_link("@user/list", :username_include_symbol => true)
|
652
|
-
linked.
|
652
|
+
expect(linked).to link_to_list_path('user/list', '@user/list')
|
653
653
|
end
|
654
654
|
|
655
655
|
it "should not add rel=nofollow when passed :suppress_no_follow" do
|
656
656
|
linked = @linker.auto_link("http://example.com/", :suppress_no_follow => true)
|
657
|
-
linked.
|
658
|
-
linked.
|
657
|
+
expect(linked).to have_autolinked_url('http://example.com/')
|
658
|
+
expect(linked).to_not match(/nofollow/)
|
659
659
|
end
|
660
660
|
|
661
661
|
it "should not add a target attribute by default" do
|
662
662
|
linked = @linker.auto_link("http://example.com/")
|
663
|
-
linked.
|
664
|
-
linked.
|
663
|
+
expect(linked).to have_autolinked_url('http://example.com/')
|
664
|
+
expect(linked).to_not match(/target=/)
|
665
665
|
end
|
666
666
|
|
667
667
|
it "should respect the :target option" do
|
668
668
|
linked = @linker.auto_link("http://example.com/", :target => 'mywindow')
|
669
|
-
linked.
|
670
|
-
linked.
|
669
|
+
expect(linked).to have_autolinked_url('http://example.com/')
|
670
|
+
expect(linked).to match(/target="mywindow"/)
|
671
671
|
end
|
672
672
|
|
673
673
|
it "should customize href by username_url_block option" do
|
674
674
|
linked = @linker.auto_link("@test", :username_url_block => lambda{|a| "dummy"})
|
675
|
-
linked.
|
675
|
+
expect(linked).to have_autolinked_url('dummy', 'test')
|
676
676
|
end
|
677
677
|
|
678
678
|
it "should customize href by list_url_block option" do
|
679
679
|
linked = @linker.auto_link("@test/list", :list_url_block => lambda{|a| "dummy"})
|
680
|
-
linked.
|
680
|
+
expect(linked).to have_autolinked_url('dummy', 'test/list')
|
681
681
|
end
|
682
682
|
|
683
683
|
it "should customize href by hashtag_url_block option" do
|
684
684
|
linked = @linker.auto_link("#hashtag", :hashtag_url_block => lambda{|a| "dummy"})
|
685
|
-
linked.
|
685
|
+
expect(linked).to have_autolinked_url('dummy', '#hashtag')
|
686
686
|
end
|
687
687
|
|
688
688
|
it "should customize href by cashtag_url_block option" do
|
689
689
|
linked = @linker.auto_link("$CASH", :cashtag_url_block => lambda{|a| "dummy"})
|
690
|
-
linked.
|
690
|
+
expect(linked).to have_autolinked_url('dummy', '$CASH')
|
691
691
|
end
|
692
692
|
|
693
693
|
it "should customize href by link_url_block option" do
|
694
694
|
linked = @linker.auto_link("http://example.com/", :link_url_block => lambda{|a| "dummy"})
|
695
|
-
linked.
|
695
|
+
expect(linked).to have_autolinked_url('dummy', 'http://example.com/')
|
696
696
|
end
|
697
697
|
|
698
698
|
it "should modify link attributes by link_attribute_block" do
|
@@ -701,17 +701,17 @@ describe Twitter::Autolink do
|
|
701
701
|
attributes[:"dummy-hash-attr"] = "test" if entity[:hashtag]
|
702
702
|
}
|
703
703
|
)
|
704
|
-
linked.
|
705
|
-
linked.
|
706
|
-
linked.
|
704
|
+
expect(linked).to match(/<a[^>]+hashtag[^>]+dummy-hash-attr=\"test\"[^>]+>/)
|
705
|
+
expect(linked).to_not match(/<a[^>]+username[^>]+dummy-hash-attr=\"test\"[^>]+>/)
|
706
|
+
expect(linked).to_not match(/link_attribute_block/i)
|
707
707
|
|
708
708
|
linked = @linker.auto_link("@mention http://twitter.com/",
|
709
709
|
:link_attribute_block => lambda{|entity, attributes|
|
710
710
|
attributes["dummy-url-attr"] = entity[:url] if entity[:url]
|
711
711
|
}
|
712
712
|
)
|
713
|
-
linked.
|
714
|
-
linked.
|
713
|
+
expect(linked).to_not match(/<a[^>]+username[^>]+dummy-url-attr=\"http:\/\/twitter.com\/\"[^>]*>/)
|
714
|
+
expect(linked).to match(/<a[^>]+dummy-url-attr=\"http:\/\/twitter.com\/\"/)
|
715
715
|
end
|
716
716
|
|
717
717
|
it "should modify link text by link_text_block" do
|
@@ -720,8 +720,8 @@ describe Twitter::Autolink do
|
|
720
720
|
entity[:hashtag] ? "#replaced" : "pre_#{text}_post"
|
721
721
|
}
|
722
722
|
)
|
723
|
-
linked.
|
724
|
-
linked.
|
723
|
+
expect(linked).to match(/<a[^>]+>#replaced<\/a>/)
|
724
|
+
expect(linked).to match(/<a[^>]+>pre_mention_post<\/a>/)
|
725
725
|
|
726
726
|
linked = @linker.auto_link("#hash @mention", {
|
727
727
|
:link_text_block => lambda{|entity, text|
|
@@ -729,28 +729,28 @@ describe Twitter::Autolink do
|
|
729
729
|
},
|
730
730
|
:symbol_tag => "s", :text_with_symbol_tag => "b", :username_include_symbol => true
|
731
731
|
})
|
732
|
-
linked.
|
733
|
-
linked.
|
732
|
+
expect(linked).to match(/<a[^>]+>pre_<s>#<\/s><b>hash<\/b>_post<\/a>/)
|
733
|
+
expect(linked).to match(/<a[^>]+>pre_<s>@<\/s><b>mention<\/b>_post<\/a>/)
|
734
734
|
end
|
735
735
|
|
736
736
|
it "should apply :url_target only to auto-linked URLs" do
|
737
737
|
auto_linked = @linker.auto_link("#hashtag @mention http://test.com/", {:url_target => '_blank'})
|
738
|
-
auto_linked.
|
739
|
-
auto_linked.
|
740
|
-
auto_linked.
|
741
|
-
auto_linked.
|
742
|
-
auto_linked.
|
743
|
-
auto_linked.
|
738
|
+
expect(auto_linked).to have_autolinked_hashtag('#hashtag')
|
739
|
+
expect(auto_linked).to link_to_screen_name('mention')
|
740
|
+
expect(auto_linked).to have_autolinked_url('http://test.com/')
|
741
|
+
expect(auto_linked).to_not match(/<a[^>]+hashtag[^>]+target[^>]+>/)
|
742
|
+
expect(auto_linked).to_not match(/<a[^>]+username[^>]+target[^>]+>/)
|
743
|
+
expect(auto_linked).to match(/<a[^>]+test.com[^>]+target=\"_blank\"[^>]*>/)
|
744
744
|
end
|
745
745
|
|
746
746
|
it "should apply target='_blank' only to auto-linked URLs when :target_blank is set to true" do
|
747
747
|
auto_linked = @linker.auto_link("#hashtag @mention http://test.com/", {:target_blank => true})
|
748
|
-
auto_linked.
|
749
|
-
auto_linked.
|
750
|
-
auto_linked.
|
751
|
-
auto_linked.
|
752
|
-
auto_linked.
|
753
|
-
auto_linked.
|
748
|
+
expect(auto_linked).to have_autolinked_hashtag('#hashtag')
|
749
|
+
expect(auto_linked).to link_to_screen_name('mention')
|
750
|
+
expect(auto_linked).to have_autolinked_url('http://test.com/')
|
751
|
+
expect(auto_linked).to match(/<a[^>]+hashtag[^>]+target=\"_blank\"[^>]*>/)
|
752
|
+
expect(auto_linked).to match(/<a[^>]+username[^>]+target=\"_blank\"[^>]*>/)
|
753
|
+
expect(auto_linked).to match(/<a[^>]+test.com[^>]+target=\"_blank\"[^>]*>/)
|
754
754
|
end
|
755
755
|
end
|
756
756
|
|
@@ -760,39 +760,39 @@ describe Twitter::Autolink do
|
|
760
760
|
end
|
761
761
|
|
762
762
|
it "should use display_url and expanded_url" do
|
763
|
-
@linker.send(:link_url_with_entity,
|
763
|
+
expect(@linker.send(:link_url_with_entity,
|
764
764
|
{
|
765
765
|
:url => "http://t.co/abcde",
|
766
766
|
:display_url => "twitter.com",
|
767
767
|
:expanded_url => "http://twitter.com/"},
|
768
|
-
{:invisible_tag_attrs => "class='invisible'"}).gsub('"', "'").
|
768
|
+
{:invisible_tag_attrs => "class='invisible'"}).gsub('"', "'")).to be == "<span class='tco-ellipsis'><span class='invisible'> </span></span><span class='invisible'>http://</span><span class='js-display-url'>twitter.com</span><span class='invisible'>/</span><span class='tco-ellipsis'><span class='invisible'> </span></span>";
|
769
769
|
end
|
770
770
|
|
771
771
|
it "should correctly handle display_url ending with '…'" do
|
772
|
-
@linker.send(:link_url_with_entity,
|
772
|
+
expect(@linker.send(:link_url_with_entity,
|
773
773
|
{
|
774
774
|
:url => "http://t.co/abcde",
|
775
775
|
:display_url => "twitter.com…",
|
776
776
|
:expanded_url => "http://twitter.com/abcdefg"},
|
777
|
-
{:invisible_tag_attrs => "class='invisible'"}).gsub('"', "'").
|
777
|
+
{:invisible_tag_attrs => "class='invisible'"}).gsub('"', "'")).to be == "<span class='tco-ellipsis'><span class='invisible'> </span></span><span class='invisible'>http://</span><span class='js-display-url'>twitter.com</span><span class='invisible'>/abcdefg</span><span class='tco-ellipsis'><span class='invisible'> </span>…</span>";
|
778
778
|
end
|
779
779
|
|
780
780
|
it "should correctly handle display_url starting with '…'" do
|
781
|
-
@linker.send(:link_url_with_entity,
|
781
|
+
expect(@linker.send(:link_url_with_entity,
|
782
782
|
{
|
783
783
|
:url => "http://t.co/abcde",
|
784
784
|
:display_url => "…tter.com/abcdefg",
|
785
785
|
:expanded_url => "http://twitter.com/abcdefg"},
|
786
|
-
{:invisible_tag_attrs => "class='invisible'"}).gsub('"', "'").
|
786
|
+
{:invisible_tag_attrs => "class='invisible'"}).gsub('"', "'")).to be == "<span class='tco-ellipsis'>…<span class='invisible'> </span></span><span class='invisible'>http://twi</span><span class='js-display-url'>tter.com/abcdefg</span><span class='invisible'></span><span class='tco-ellipsis'><span class='invisible'> </span></span>";
|
787
787
|
end
|
788
788
|
|
789
789
|
it "should not create spans if display_url and expanded_url are on different domains" do
|
790
|
-
@linker.send(:link_url_with_entity,
|
790
|
+
expect(@linker.send(:link_url_with_entity,
|
791
791
|
{
|
792
792
|
:url => "http://t.co/abcde",
|
793
793
|
:display_url => "pic.twitter.com/xyz",
|
794
794
|
:expanded_url => "http://twitter.com/foo/statuses/123/photo/1"},
|
795
|
-
{:invisible_tag_attrs => "class='invisible'"}).gsub('"', "'").
|
795
|
+
{:invisible_tag_attrs => "class='invisible'"}).gsub('"', "'")).to be == "pic.twitter.com/xyz"
|
796
796
|
end
|
797
797
|
end
|
798
798
|
|
@@ -801,24 +801,24 @@ describe Twitter::Autolink do
|
|
801
801
|
@linker = TestAutolink.new
|
802
802
|
end
|
803
803
|
it "should put :symbol_tag around symbol" do
|
804
|
-
@linker.auto_link("@mention", {:symbol_tag => 's', :username_include_symbol=>true}).
|
805
|
-
@linker.auto_link("#hash", {:symbol_tag => 's'}).
|
804
|
+
expect(@linker.auto_link("@mention", {:symbol_tag => 's', :username_include_symbol=>true})).to match(/<s>@<\/s>mention/)
|
805
|
+
expect(@linker.auto_link("#hash", {:symbol_tag => 's'})).to match(/<s>#<\/s>hash/)
|
806
806
|
result = @linker.auto_link("@mention #hash $CASH", {:symbol_tag => 'b', :username_include_symbol=>true})
|
807
|
-
result.
|
808
|
-
result.
|
809
|
-
result.
|
807
|
+
expect(result).to match(/<b>@<\/b>mention/)
|
808
|
+
expect(result).to match(/<b>#<\/b>hash/)
|
809
|
+
expect(result).to match(/<b>\$<\/b>CASH/)
|
810
810
|
end
|
811
811
|
it "should put :text_with_symbol_tag around text" do
|
812
812
|
result = @linker.auto_link("@mention #hash $CASH", {:text_with_symbol_tag => 'b'})
|
813
|
-
result.
|
814
|
-
result.
|
815
|
-
result.
|
813
|
+
expect(result).to match(/<b>mention<\/b>/)
|
814
|
+
expect(result).to match(/<b>hash<\/b>/)
|
815
|
+
expect(result).to match(/<b>CASH<\/b>/)
|
816
816
|
end
|
817
817
|
it "should put :symbol_tag around symbol and :text_with_symbol_tag around text" do
|
818
818
|
result = @linker.auto_link("@mention #hash $CASH", {:symbol_tag => 's', :text_with_symbol_tag => 'b', :username_include_symbol=>true})
|
819
|
-
result.
|
820
|
-
result.
|
821
|
-
result.
|
819
|
+
expect(result).to match(/<s>@<\/s><b>mention<\/b>/)
|
820
|
+
expect(result).to match(/<s>#<\/s><b>hash<\/b>/)
|
821
|
+
expect(result).to match(/<s>\$<\/s><b>CASH<\/b>/)
|
822
822
|
end
|
823
823
|
end
|
824
824
|
|
@@ -827,17 +827,17 @@ describe Twitter::Autolink do
|
|
827
827
|
@linker = TestAutolink.new
|
828
828
|
end
|
829
829
|
it "should escape html entities properly" do
|
830
|
-
@linker.html_escape("&").
|
831
|
-
@linker.html_escape(">").
|
832
|
-
@linker.html_escape("<").
|
833
|
-
@linker.html_escape("\"").
|
834
|
-
@linker.html_escape("'").
|
835
|
-
@linker.html_escape("&<>\"").
|
836
|
-
@linker.html_escape("<div>").
|
837
|
-
@linker.html_escape("a&b").
|
838
|
-
@linker.html_escape("<a href=\"https://twitter.com\" target=\"_blank\">twitter & friends</a>").
|
839
|
-
@linker.html_escape("&").
|
840
|
-
@linker.html_escape(nil).
|
830
|
+
expect(@linker.html_escape("&")).to be == "&"
|
831
|
+
expect(@linker.html_escape(">")).to be == ">"
|
832
|
+
expect(@linker.html_escape("<")).to be == "<"
|
833
|
+
expect(@linker.html_escape("\"")).to be == """
|
834
|
+
expect(@linker.html_escape("'")).to be == "'"
|
835
|
+
expect(@linker.html_escape("&<>\"")).to be == "&<>""
|
836
|
+
expect(@linker.html_escape("<div>")).to be == "<div>"
|
837
|
+
expect(@linker.html_escape("a&b")).to be == "a&b"
|
838
|
+
expect(@linker.html_escape("<a href=\"https://twitter.com\" target=\"_blank\">twitter & friends</a>")).to be == "<a href="https://twitter.com" target="_blank">twitter & friends</a>"
|
839
|
+
expect(@linker.html_escape("&")).to be == "&amp;"
|
840
|
+
expect(@linker.html_escape(nil)).to be == nil
|
841
841
|
end
|
842
842
|
end
|
843
843
|
|