|
5 | 5 | expect(ActiveRecord::Base).to respond_to(:user_html) |
6 | 6 | end |
7 | 7 |
|
8 | | - it 'converts url\'s to html anchors with rel="nofollow" and target="_blank"' do |
| 8 | + it 'does not auto_link urls' do |
9 | 9 | content = 'Here is a cool link: http://www.example.com.' |
10 | | - expect(described_class.link_and_sanitize(content)).to( |
11 | | - eq 'Here is a cool link: <a href="http://www.example.com" ' + |
12 | | - 'rel="nofollow" target="_blank">http://www.example.com</a>.' |
13 | | - ) |
| 10 | + expect(described_class.sanitize(content)).to eq content |
14 | 11 | end |
15 | 12 |
|
16 | 13 | it 'adds rel="nofollow" and target="_blank" to existing html anchors' do |
17 | 14 | content = 'Here is a cooler link: <a href="https://www.example.com">Example</a>.' |
18 | | - expect(described_class.link_and_sanitize(content)).to( |
| 15 | + expect(described_class.sanitize(content)).to( |
19 | 16 | eq 'Here is a cooler link: <a href="https://www.example.com" ' + |
20 | 17 | 'rel="nofollow" target="_blank">Example</a>.' |
21 | 18 | ) |
22 | 19 | end |
23 | 20 |
|
24 | 21 | it 'removes script tags' do |
25 | 22 | content = 'Have a cup of <script>1337 $cr1pt</script>.' |
26 | | - expect(described_class.link_and_sanitize(content)).to eq 'Have a cup of .' |
| 23 | + expect(described_class.sanitize(content)).to eq 'Have a cup of .' |
27 | 24 | end |
28 | 25 |
|
29 | 26 | it 'allows iframes to whitelisted domains' do |
|
34 | 31 | 'src="https://www.youtube.com/embed/Xp6V_lO1ZKA" frameborder="0" ' + |
35 | 32 | 'allowfullscreen=""></iframe>' |
36 | 33 |
|
37 | | - expect(described_class.link_and_sanitize(youtube_content)).to eq expected_youtube_content |
| 34 | + expect(described_class.sanitize(youtube_content)).to eq expected_youtube_content |
38 | 35 |
|
39 | 36 | khan_content = \ |
40 | 37 | "<a style=\"color: #111; font-family: helvetica;\" target=\"_blank\" " + |
|
57 | 54 | "src=\"https://www.khanacademy.org/embed_video?v=Xp6V_lO1ZKA\" allowfullscreen=\"\" " + |
58 | 55 | "webkitallowfullscreen=\"\" mozallowfullscreen=\"\"></iframe>" |
59 | 56 |
|
60 | | - expect(described_class.link_and_sanitize(khan_content)).to eq expected_khan_content |
| 57 | + expect(described_class.sanitize(khan_content)).to eq expected_khan_content |
61 | 58 |
|
62 | 59 | end |
63 | 60 |
|
|
68 | 65 | https://server2.cnx.org/content |
69 | 66 | } |
70 | 67 | valid_urls.each do | url | |
71 | | - expect(described_class.link_and_sanitize( |
| 68 | + expect(described_class.sanitize( |
72 | 69 | "<iframe src='#{url}' />" |
73 | 70 | )).to eq "<iframe src=\"#{url}\"></iframe>" |
74 | 71 | end |
75 | 72 | end |
76 | 73 |
|
77 | 74 | it 'removes iframes to non-whitelisted domains' do |
78 | 75 | content = "Funny cat videos: <iframe src=\"http://mal.icio.us\">" |
79 | | - expect(described_class.link_and_sanitize(content)).to eq 'Funny cat videos: ' |
| 76 | + expect(described_class.sanitize(content)).to eq 'Funny cat videos: ' |
80 | 77 | end |
81 | 78 |
|
82 | 79 | describe 'data-math attribute' do |
83 | 80 | let (:formula){ %-\lim_{x\to\infty}f(x)=0- } |
84 | 81 |
|
85 | 82 | it 'is allowed on divs' do |
86 | 83 | content = "as a block: <div data-math='#{formula}'/>" |
87 | | - expect(described_class.link_and_sanitize(content)).to eq "as a block: <div data-math=\"#{formula}\"></div>" |
| 84 | + expect(described_class.sanitize(content)).to eq "as a block: <div data-math=\"#{formula}\"></div>" |
88 | 85 | end |
89 | 86 |
|
90 | 87 | it 'is allowed on spans' do |
91 | 88 | content = "as inline: <span data-math='#{formula}'/>" |
92 | | - expect(described_class.link_and_sanitize(content)).to eq "as inline: <span data-math=\"#{formula}\"></span>" |
| 89 | + expect(described_class.sanitize(content)).to eq "as inline: <span data-math=\"#{formula}\"></span>" |
93 | 90 | end |
94 | 91 |
|
95 | 92 | it 'is removed from other elements' do |
96 | 93 | content = "also: <p data-math='#{formula}'/>" |
97 | | - expect(described_class.link_and_sanitize(content)).to eq 'also: <p></p>' |
| 94 | + expect(described_class.sanitize(content)).to eq 'also: <p></p>' |
98 | 95 | end |
99 | 96 |
|
100 | 97 | end |
|
0 commit comments