ruby-bbcode 2.0.0 → 2.1.1
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 +5 -5
- data/CHANGELOG.md +31 -2
- data/README.md +66 -0
- data/Rakefile +2 -4
- data/lib/ruby-bbcode.rb +48 -28
- data/lib/ruby-bbcode/bbtree.rb +20 -12
- data/lib/ruby-bbcode/configuration.rb +18 -0
- data/lib/ruby-bbcode/tag_collection.rb +9 -9
- data/lib/ruby-bbcode/tag_info.rb +49 -18
- data/lib/ruby-bbcode/tag_node.rb +4 -4
- data/lib/ruby-bbcode/tag_sifter.rb +80 -57
- data/lib/ruby-bbcode/templates/bbcode_errors_template.rb +20 -17
- data/lib/ruby-bbcode/templates/html_template.rb +36 -10
- data/lib/ruby-bbcode/version.rb +1 -1
- data/lib/tags/tags.rb +126 -104
- data/test/ruby_bbcode_bbcode_test.rb +39 -16
- data/test/ruby_bbcode_html_test.rb +68 -40
- data/test/ruby_bbcode_validity_test.rb +22 -19
- data/test/test_helper.rb +4 -5
- data/test/unit/configuration_test.rb +37 -0
- data/test/unit/tag_sifter_test.rb +7 -9
- data/test/unit/tags_test.rb +2 -2
- metadata +76 -18
- data/README.textile +0 -56
data/lib/ruby-bbcode/version.rb
CHANGED
data/lib/tags/tags.rb
CHANGED
@@ -6,127 +6,149 @@ module RubyBBCode
|
|
6
6
|
# A single item from this file (eg the :b entry) is refered to as a @definition
|
7
7
|
@@tags = {
|
8
8
|
:b => {
|
9
|
-
:
|
10
|
-
:
|
11
|
-
:
|
9
|
+
html_open: '<strong>', html_close: '</strong>',
|
10
|
+
description: 'Make text bold',
|
11
|
+
example: 'This is [b]bold[/b].'
|
12
|
+
},
|
12
13
|
:i => {
|
13
|
-
:
|
14
|
-
:
|
15
|
-
:
|
14
|
+
html_open: '<em>', html_close: '</em>',
|
15
|
+
description: 'Make text italic',
|
16
|
+
example: 'This is [i]italic[/i].'
|
17
|
+
},
|
16
18
|
:u => {
|
17
|
-
:
|
18
|
-
:
|
19
|
-
:
|
19
|
+
html_open: '<u>', html_close: '</u>',
|
20
|
+
description: 'Underline text',
|
21
|
+
example: 'This is [u]underlined[/u].'
|
22
|
+
},
|
20
23
|
:s => {
|
21
|
-
:
|
22
|
-
:
|
23
|
-
:
|
24
|
+
html_open: '<span style="text-decoration:line-through;">', html_close: '</span>',
|
25
|
+
description: 'Strike-through text',
|
26
|
+
example: 'This is [s]wrong[/s] good.'
|
27
|
+
},
|
24
28
|
:center => {
|
25
|
-
:
|
26
|
-
:
|
27
|
-
:
|
29
|
+
html_open: '<div style="text-align:center;">', html_close: '</div>',
|
30
|
+
description: 'Center a text',
|
31
|
+
example: '[center]This is centered[/center].'
|
32
|
+
},
|
28
33
|
:ul => {
|
29
|
-
:
|
30
|
-
:
|
31
|
-
:
|
32
|
-
:
|
34
|
+
html_open: '<ul>', html_close: '</ul>',
|
35
|
+
description: 'Unordered list',
|
36
|
+
block_tag: true,
|
37
|
+
example: '[ul][li]List item[/li][li]Another list item[/li][/ul].',
|
38
|
+
only_allow: [:li, '*'.to_sym]
|
39
|
+
},
|
33
40
|
:code => {
|
34
|
-
:
|
35
|
-
:
|
36
|
-
:
|
41
|
+
html_open: '<pre>', html_close: '</pre>',
|
42
|
+
description: 'Code block with mono-spaced text',
|
43
|
+
example: 'This is [code]mono-spaced code[/code].',
|
44
|
+
block_tag: true
|
45
|
+
},
|
37
46
|
:ol => {
|
38
|
-
:
|
39
|
-
:
|
40
|
-
:
|
41
|
-
:
|
47
|
+
html_open: '<ol>', html_close: '</ol>',
|
48
|
+
description: 'Ordered list',
|
49
|
+
example: '[ol][li]List item[/li][li]Another list item[/li][/ol].',
|
50
|
+
block_tag: true,
|
51
|
+
only_allow: [:li, '*'.to_sym]
|
52
|
+
},
|
42
53
|
:li => {
|
43
|
-
:
|
44
|
-
:
|
45
|
-
:
|
46
|
-
:
|
54
|
+
html_open: '<li>', html_close: '</li>',
|
55
|
+
description: 'List item',
|
56
|
+
example: '[ul][li]List item[/li][li]Another list item[/li][/ul].',
|
57
|
+
block_tag: true,
|
58
|
+
only_in: %i[ul ol]
|
59
|
+
},
|
47
60
|
:list => {
|
48
|
-
:
|
49
|
-
:
|
50
|
-
:
|
51
|
-
:
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
:
|
56
|
-
:
|
57
|
-
:
|
61
|
+
html_open: '<ul>', html_close: '</ul>',
|
62
|
+
description: 'Unordered list',
|
63
|
+
example: '[list][*]List item[*]Another list item[/list].',
|
64
|
+
block_tag: true,
|
65
|
+
only_allow: ['*'.to_sym]
|
66
|
+
},
|
67
|
+
'*'.to_sym => {
|
68
|
+
html_open: '<li>', html_close: '</li>',
|
69
|
+
description: 'List item',
|
70
|
+
example: '[list][*]List item[*]Another list item[/list].',
|
71
|
+
self_closable: true, block_tag: true,
|
72
|
+
only_in: %i[list ul ol]
|
73
|
+
},
|
58
74
|
:img => {
|
59
|
-
:
|
60
|
-
:
|
61
|
-
:
|
62
|
-
:
|
63
|
-
:
|
64
|
-
:
|
65
|
-
:
|
66
|
-
:
|
67
|
-
|
68
|
-
:
|
75
|
+
html_open: '<img src="%between%" %width%%height%alt="" />', html_close: '',
|
76
|
+
description: 'Image',
|
77
|
+
example: '[img]http://www.google.com/intl/en_ALL/images/logo.gif[/img].',
|
78
|
+
only_allow: [],
|
79
|
+
require_between: true,
|
80
|
+
allow_quick_param: true, allow_between_as_param: false, block_tag: true,
|
81
|
+
quick_param_format: /^(\d+)x(\d+)$/,
|
82
|
+
param_tokens: [{ token: :width, prefix: 'width="', postfix: '" ', optional: true },
|
83
|
+
{ token: :height, prefix: 'height="', postfix: '" ', optional: true }],
|
84
|
+
quick_param_format_description: 'The image parameters \'%param%\' are incorrect, \'<width>x<height>\' excepted'
|
85
|
+
},
|
69
86
|
:url => {
|
70
|
-
:
|
71
|
-
:
|
72
|
-
:
|
73
|
-
:
|
74
|
-
:
|
75
|
-
:
|
76
|
-
:
|
77
|
-
:
|
78
|
-
|
87
|
+
html_open: '<a href="%url%">%between%', html_close: '</a>',
|
88
|
+
description: 'Link to another page',
|
89
|
+
example: '[url]http://www.google.com/[/url].',
|
90
|
+
require_between: true,
|
91
|
+
allow_quick_param: true, allow_between_as_param: true,
|
92
|
+
quick_param_format: %r{^((((http|https|ftp)://)|/).+)$},
|
93
|
+
quick_param_format_description: 'The URL should start with http:// https://, ftp:// or /, instead of \'%param%\'',
|
94
|
+
param_tokens: [{ token: :url }]
|
95
|
+
},
|
79
96
|
:quote => {
|
80
|
-
:
|
81
|
-
:
|
82
|
-
:
|
83
|
-
:
|
84
|
-
:
|
85
|
-
:
|
97
|
+
html_open: '<div class="quote">%author%', html_close: '</div>',
|
98
|
+
description: 'Quote another person',
|
99
|
+
example: '[quote]BBCode is great[/quote]',
|
100
|
+
allow_quick_param: true, allow_between_as_param: false, block_tag: true,
|
101
|
+
quick_param_format: /(.*)/,
|
102
|
+
param_tokens: [{ token: :author, prefix: '<strong>', postfix: ' wrote:</strong>', optional: true }]
|
103
|
+
},
|
86
104
|
:size => {
|
87
|
-
:
|
88
|
-
:
|
89
|
-
:
|
90
|
-
:
|
91
|
-
:
|
92
|
-
:
|
93
|
-
:
|
105
|
+
html_open: '<span style="font-size: %size%px;">', html_close: '</span>',
|
106
|
+
description: 'Change the size of the text',
|
107
|
+
example: '[size=32]This is 32px[/size]',
|
108
|
+
allow_quick_param: true, allow_between_as_param: false,
|
109
|
+
quick_param_format: /(\d+)/,
|
110
|
+
quick_param_format_description: 'The size parameter \'%param%\' is incorrect, a number is expected',
|
111
|
+
param_tokens: [{ token: :size }]
|
112
|
+
},
|
94
113
|
:color => {
|
95
|
-
:
|
96
|
-
:
|
97
|
-
:
|
98
|
-
:
|
99
|
-
:
|
100
|
-
:
|
114
|
+
html_open: '<span style="color: %color%;">', html_close: '</span>',
|
115
|
+
description: 'Change the color of the text',
|
116
|
+
example: '[color=red]This is red[/color]',
|
117
|
+
allow_quick_param: true, allow_between_as_param: false,
|
118
|
+
quick_param_format: /(([a-z]+)|(#[0-9a-f]{6}))/i,
|
119
|
+
param_tokens: [{ token: :color }]
|
120
|
+
},
|
101
121
|
:youtube => {
|
102
|
-
:
|
103
|
-
:
|
104
|
-
:
|
105
|
-
:
|
106
|
-
:
|
107
|
-
:
|
108
|
-
:
|
109
|
-
{ :
|
110
|
-
{ :
|
111
|
-
]
|
122
|
+
html_open: '<iframe id="player" type="text/html" width="%width%" height="%height%" src="http://www.youtube.com/embed/%between%?enablejsapi=1" frameborder="0"></iframe>', html_close: '',
|
123
|
+
description: 'YouTube video',
|
124
|
+
example: '[youtube]E4Fbk52Mk1w[/youtube]',
|
125
|
+
only_allow: [],
|
126
|
+
url_matches: [/youtube\.com.*[v]=([^&]*)/, %r{youtu\.be/([^&]*)}, %r{y2u\.be/([^&]*)}],
|
127
|
+
require_between: true, block_tag: true,
|
128
|
+
param_tokens: [
|
129
|
+
{ token: :width, optional: true, default: 400 },
|
130
|
+
{ token: :height, optional: true, default: 320 }
|
131
|
+
]
|
132
|
+
},
|
112
133
|
:vimeo => {
|
113
|
-
:
|
114
|
-
:
|
115
|
-
:
|
116
|
-
:
|
117
|
-
:
|
118
|
-
:
|
119
|
-
:
|
120
|
-
:
|
121
|
-
{ :
|
122
|
-
{ :
|
123
|
-
]
|
134
|
+
html_open: '<iframe src="http://player.vimeo.com/video/%between%?badge=0" width="%width%" height="%height%" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>',
|
135
|
+
html_close: '',
|
136
|
+
description: 'Vimeo video',
|
137
|
+
example: '[vimeo]http://vimeo.com/46141955[/vimeo]',
|
138
|
+
only_allow: [],
|
139
|
+
url_matches: [%r{vimeo\.com/([^&]*)}],
|
140
|
+
require_between: true, block_tag: true,
|
141
|
+
param_tokens: [
|
142
|
+
{ token: :width, optional: true, default: 400 },
|
143
|
+
{ token: :height, optional: true, default: 320 }
|
144
|
+
]
|
145
|
+
},
|
124
146
|
:media => {
|
125
|
-
:
|
126
|
-
:
|
127
|
-
:
|
128
|
-
|
129
|
-
|
147
|
+
multi_tag: true,
|
148
|
+
require_between: true,
|
149
|
+
supported_tags: %i[
|
150
|
+
youtube
|
151
|
+
vimeo
|
130
152
|
]
|
131
153
|
}
|
132
154
|
}
|
@@ -1,6 +1,9 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class RubyBbcodeBbcodeTest < Minitest::Test
|
4
|
+
def before_setup
|
5
|
+
RubyBBCode.reset
|
6
|
+
end
|
4
7
|
|
5
8
|
def test_multiline
|
6
9
|
assert_equal "line1\nline2", "line1\nline2".bbcode_show_errors
|
@@ -47,14 +50,17 @@ class RubyBbcodeBbcodeTest < Minitest::Test
|
|
47
50
|
|
48
51
|
def test_ordered_list
|
49
52
|
assert_equal '[ol][li]item 1[/li][li]item 2[/li][/ol]', '[ol][li]item 1[/li][li]item 2[/li][/ol]'.bbcode_show_errors
|
53
|
+
assert_equal "[ol]\n[li]item 1[/li]\n[li]item 2[/li]\n[/ol]", "[ol]\n[li]item 1[/li]\n[li]item 2[/li]\n[/ol]".bbcode_show_errors
|
50
54
|
end
|
51
55
|
|
52
56
|
def test_unordered_list
|
53
57
|
assert_equal '[ul][li]item 1[/li][li]item 2[/li][/ul]', '[ul][li]item 1[/li][li]item 2[/li][/ul]'.bbcode_show_errors
|
58
|
+
assert_equal "[ul]\n\t[li]item 1[/li]\n\t[li]item 2[/li]\n[/ul]", "[ul]\n\t[li]item 1[/li]\n\t[li]item 2[/li]\n[/ul]".bbcode_show_errors
|
54
59
|
end
|
55
60
|
|
56
61
|
def test_list_common_syntax
|
57
62
|
assert_equal '[list][*]item 1[/*][*]item 2[/*][/list]', '[list][*]item 1[*]item 2[/list]'.bbcode_show_errors
|
63
|
+
assert_equal "[list]\n[*]item 1[/*]\n[*]item 2[/*]\n[/list]", "[list]\n[*]item 1\n[*]item 2\n[/list]".bbcode_show_errors
|
58
64
|
end
|
59
65
|
|
60
66
|
def test_list_common_syntax_explicit_closing
|
@@ -63,51 +69,53 @@ class RubyBbcodeBbcodeTest < Minitest::Test
|
|
63
69
|
|
64
70
|
def test_two_lists
|
65
71
|
assert_equal '[ul][li]item1[/li][li]item2[/li][/ul][ul][li]item1[/li][li]item2[/li][/ul]',
|
66
|
-
|
72
|
+
'[ul][li]item1[/li][li]item2[/li][/ul][ul][li]item1[/li][li]item2[/li][/ul]'.bbcode_show_errors
|
67
73
|
end
|
68
74
|
|
69
75
|
def test_whitespace_in_only_allowed_tags
|
70
76
|
assert_equal "[ol]\n[li]item 1[/li]\n[li]item 2[/li]\n[/ol]",
|
71
|
-
|
77
|
+
"[ol]\n[li]item 1[/li]\n[li]item 2[/li]\n[/ol]".bbcode_show_errors
|
72
78
|
assert_equal "[ol] [li]item 1[/li] [li]item 2[/li]\t[/ol]",
|
73
|
-
|
79
|
+
"[ol] [li]item 1[/li] [li]item 2[/li]\t[/ol]".bbcode_show_errors
|
74
80
|
end
|
75
81
|
|
76
82
|
def test_quote
|
77
83
|
assert_equal '[quote]quoting[/quote]', '[quote]quoting[/quote]'.bbcode_show_errors
|
84
|
+
assert_equal "[quote]\nquoting\n[/quote]", "[quote]\nquoting\n[/quote]".bbcode_show_errors
|
78
85
|
assert_equal '[quote author=someone]quoting[/quote]', '[quote=someone]quoting[/quote]'.bbcode_show_errors
|
79
86
|
assert_equal '[quote author=Kitten][quote author=creatiu]f1[/quote]f2[/quote]',
|
80
|
-
|
87
|
+
'[quote author=Kitten][quote=creatiu]f1[/quote]f2[/quote]'.bbcode_show_errors
|
81
88
|
end
|
82
89
|
|
83
90
|
def test_link
|
84
91
|
assert_equal '[url url=http://www.google.com]http://www.google.com[/url]', '[url]http://www.google.com[/url]'.bbcode_show_errors
|
85
92
|
assert_equal '[url url=http://google.com]Google[/url]', '[url=http://google.com]Google[/url]'.bbcode_show_errors
|
93
|
+
assert_equal '[url url=http://google.com][b]Bold Google[/b][/url]', '[url=http://google.com][b]Bold Google[/b][/url]'.bbcode_show_errors
|
86
94
|
assert_equal '[url url=/index.html]Home[/url]', '[url=/index.html]Home[/url]'.bbcode_show_errors
|
87
95
|
end
|
88
96
|
|
89
97
|
def test_image
|
90
98
|
assert_equal '[img]http://www.ruby-lang.org/images/logo.gif[/img]',
|
91
|
-
|
99
|
+
'[img]http://www.ruby-lang.org/images/logo.gif[/img]'.bbcode_show_errors
|
92
100
|
assert_equal '[img width=95 height=96]http://www.ruby-lang.org/images/logo.gif[/img]',
|
93
|
-
|
101
|
+
'[img=95x96]http://www.ruby-lang.org/images/logo.gif[/img]'.bbcode_show_errors
|
94
102
|
assert_equal '[img width=123 height=456]http://www.ruby-lang.org/images/logo.gif[/img]',
|
95
|
-
|
103
|
+
'[img width=123 height=456]http://www.ruby-lang.org/images/logo.gif[/img]'.bbcode_show_errors
|
96
104
|
end
|
97
105
|
|
98
106
|
def test_youtube
|
99
107
|
assert_equal '[youtube]E4Fbk52Mk1w[/youtube]',
|
100
|
-
|
108
|
+
'[youtube]E4Fbk52Mk1w[/youtube]'.bbcode_show_errors
|
101
109
|
end
|
102
110
|
|
103
111
|
def test_youtube_with_full_url
|
104
112
|
assert_equal '[youtube]E4Fbk52Mk1w[/youtube]',
|
105
|
-
|
113
|
+
'[youtube]http://www.youtube.com/watch?feature=player_embedded&v=E4Fbk52Mk1w[/youtube]'.bbcode_show_errors
|
106
114
|
end
|
107
115
|
|
108
116
|
def test_youtube_with_url_shortener
|
109
117
|
assert_equal '[youtube]cSohjlYQI2A[/youtube]',
|
110
|
-
|
118
|
+
'[youtube]http://www.youtu.be/cSohjlYQI2A[/youtube]'.bbcode_show_errors
|
111
119
|
end
|
112
120
|
|
113
121
|
def test_disable_tags
|
@@ -117,17 +125,18 @@ class RubyBbcodeBbcodeTest < Minitest::Test
|
|
117
125
|
end
|
118
126
|
|
119
127
|
def test_enable_tags
|
120
|
-
assert_equal '[b]foobar[/b]'
|
128
|
+
assert_equal '[b]foobar[/b]', '[b]foobar[/b]'.bbcode_show_errors({}, :enable, :b)
|
121
129
|
assert_equal '[b][i]foobar[/i][/b]', '[b][i]foobar[/i][/b]'.bbcode_show_errors({}, :enable, :b)
|
122
130
|
assert_equal '[b][i]foobar[/i][/b]', '[b][i]foobar[/i][/b]'.bbcode_show_errors({}, :enable, :b, :i)
|
123
131
|
end
|
124
132
|
|
125
133
|
def test_addition_of_tags
|
126
134
|
mydef = {
|
127
|
-
:
|
128
|
-
:
|
129
|
-
:
|
130
|
-
:
|
135
|
+
test: {
|
136
|
+
html_open: '<test>', html_close: '</test>',
|
137
|
+
description: 'This is a test',
|
138
|
+
example: '[test]Test here[/test]'
|
139
|
+
}
|
131
140
|
}
|
132
141
|
assert_equal 'pre [test]Test here[/test] post', 'pre [test]Test here[/test] post'.bbcode_show_errors(mydef)
|
133
142
|
assert_equal 'pre [b][test]Test here[/test][/b] post', 'pre [b][test]Test here[/test][/b] post'.bbcode_show_errors(mydef)
|
@@ -135,7 +144,7 @@ class RubyBbcodeBbcodeTest < Minitest::Test
|
|
135
144
|
|
136
145
|
def test_multiple_tag_test
|
137
146
|
assert_equal '[b]bold[/b][i]italic[/i][u]underline[/u][quote]quote[/quote][url url=https://test.com]link[/url]',
|
138
|
-
|
147
|
+
'[b]bold[/b][i]italic[/i][u]underline[/u][quote]quote[/quote][url=https://test.com]link[/url]'.bbcode_show_errors
|
139
148
|
end
|
140
149
|
|
141
150
|
def test_no_xss_hax
|
@@ -176,12 +185,26 @@ class RubyBbcodeBbcodeTest < Minitest::Test
|
|
176
185
|
def test_failing_between_texts
|
177
186
|
assert_equal '<span class=\'bbcode_error\' data-bbcode-errors=\'["No text between [img] and [/img] tags."]\'>[img]</span>[/img]', '[img][/img]'.bbcode_show_errors
|
178
187
|
assert_equal '[url]<span class=\'bbcode_error\' data-bbcode-errors=\'["The URL should start with http:// https://, ftp:// or /, instead of 'illegal url'"]\'>illegal url</span>[/url]', '[url]illegal url[/url]'.bbcode_show_errors
|
188
|
+
assert_equal '[url]<span class=\'bbcode_error\' data-bbcode-errors=\'["between parameter must be plain text"]\'>[b]</span>Bold Google[/b][/url]', '[url][b]Bold Google[/b][/url]'.bbcode_show_errors
|
179
189
|
end
|
180
190
|
|
181
191
|
def test_missing_parent_tags
|
182
192
|
assert_equal '<span class=\'bbcode_error\' data-bbcode-errors=\'["[li] can only be used in [ul] and [ol]"]\'>[li]</span>[/li]', '[li][/li]'.bbcode_show_errors
|
183
193
|
end
|
184
194
|
|
195
|
+
def test_unknown_tag
|
196
|
+
RubyBBCode.configuration.ignore_unknown_tags = :exception
|
197
|
+
assert_raises RuntimeError do
|
198
|
+
'[unknown]This is an unknown tag[/unknown]'.bbcode_show_errors
|
199
|
+
end
|
200
|
+
|
201
|
+
RubyBBCode.configuration.ignore_unknown_tags = :ignore
|
202
|
+
assert_equal 'This is an unknown tag', '[unknown]This is an unknown tag[/unknown]'.bbcode_show_errors
|
203
|
+
|
204
|
+
RubyBBCode.configuration.ignore_unknown_tags = :text
|
205
|
+
assert_equal '[unknown]This is an unknown tag[/unknown]', '[unknown]This is an unknown tag[/unknown]'.bbcode_show_errors
|
206
|
+
end
|
207
|
+
|
185
208
|
def test_illegal_unallowed_childs
|
186
209
|
assert_equal '[ul]<span class=\'bbcode_error\' data-bbcode-errors=\'["[ul] can only contain [li] and [*] tags, so "Illegal text" is not allowed"]\'>Illegal text</span>[/ul]', '[ul]Illegal text[/ul]'.bbcode_show_errors
|
187
210
|
assert_equal '[ul]<span class=\'bbcode_error\' data-bbcode-errors=\'["[ul] can only contain [li] and [*] tags, so [b] is not allowed"]\'>[b]</span>Illegal tag[/b][/ul]', '[ul][b]Illegal tag[/b][/ul]'.bbcode_show_errors
|
@@ -1,10 +1,15 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class RubyBbcodeHtmlTest < Minitest::Test
|
4
|
+
def before_setup
|
5
|
+
RubyBBCode.reset
|
6
|
+
end
|
4
7
|
|
5
8
|
def test_multiline
|
6
9
|
assert_equal "line1<br />\nline2", "line1\nline2".bbcode_to_html
|
7
10
|
assert_equal "line1<br />\nline2", "line1\r\nline2".bbcode_to_html
|
11
|
+
assert_equal "<ul>\n<li>line1</li>\n<li>line2</li>\n</ul>", "[ul]\n[li]line1[/li]\n[li]line2[/li]\n[/ul]".bbcode_to_html
|
12
|
+
assert_equal "<strong><br />\nline 1<br />\nline 2</strong>", "[b]\nline 1\nline 2[/b]".bbcode_to_html
|
8
13
|
end
|
9
14
|
|
10
15
|
def test_strong
|
@@ -55,6 +60,11 @@ class RubyBbcodeHtmlTest < Minitest::Test
|
|
55
60
|
|
56
61
|
def test_list_common_syntax
|
57
62
|
assert_equal '<ul><li>item 1</li><li>item 2</li></ul>', '[list][*]item 1[*]item 2[/list]'.bbcode_to_html
|
63
|
+
assert_equal '<ul><li><strong>item 1</strong> test</li><li>item 2</li></ul>', '[list][*][b]item 1[/b] test[*]item 2[/list]'.bbcode_to_html
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_newline_list_common_syntax
|
67
|
+
assert_equal "<ul>\n<li>item 1</li>\n<li>item 2</li>\n\n</ul>", "[list]\n[*]item 1\n[*]item 2\n\n[/list]".bbcode_to_html
|
58
68
|
end
|
59
69
|
|
60
70
|
def test_list_common_syntax_explicit_closing
|
@@ -63,55 +73,58 @@ class RubyBbcodeHtmlTest < Minitest::Test
|
|
63
73
|
|
64
74
|
def test_two_lists
|
65
75
|
assert_equal '<ul><li>item1</li><li>item2</li></ul><ul><li>item1</li><li>item2</li></ul>',
|
66
|
-
|
76
|
+
'[ul][li]item1[/li][li]item2[/li][/ul][ul][li]item1[/li][li]item2[/li][/ul]'.bbcode_to_html
|
67
77
|
end
|
68
78
|
|
69
79
|
def test_whitespace_in_only_allowed_tags
|
70
|
-
assert_equal "<ol
|
71
|
-
|
80
|
+
assert_equal "<ol>\n<li>item 1</li>\n<li>item 2</li>\n</ol>",
|
81
|
+
"[ol]\n[li]item 1[/li]\n[li]item 2[/li]\n[/ol]".bbcode_to_html
|
72
82
|
assert_equal "<ol> <li>item 1</li> <li>item 2</li>\t</ol>",
|
73
|
-
|
83
|
+
"[ol] [li]item 1[/li] [li]item 2[/li]\t[/ol]".bbcode_to_html
|
74
84
|
end
|
75
85
|
|
76
86
|
def test_quote
|
77
87
|
assert_equal '<div class="quote">quoting</div>', '[quote]quoting[/quote]'.bbcode_to_html
|
88
|
+
assert_equal "<div class=\"quote\">\nquoting\n</div>", "[quote]\nquoting\n[/quote]".bbcode_to_html
|
89
|
+
assert_equal "<div class=\"quote\">\nfirst line<br />\nsecond line\n</div>", "[quote]\nfirst line\nsecond line\n[/quote]".bbcode_to_html
|
78
90
|
assert_equal '<div class="quote"><strong>someone wrote:</strong>quoting</div>', '[quote=someone]quoting[/quote]'.bbcode_to_html
|
79
91
|
assert_equal '<div class="quote"><strong>Kitten wrote:</strong><div class="quote"><strong>creatiu wrote:</strong>f1</div>f2</div>',
|
80
|
-
|
92
|
+
'[quote=Kitten][quote=creatiu]f1[/quote]f2[/quote]'.bbcode_to_html
|
81
93
|
end
|
82
94
|
|
83
95
|
def test_link
|
84
96
|
assert_equal '<a href="http://www.google.com">http://www.google.com</a>', '[url]http://www.google.com[/url]'.bbcode_to_html
|
85
97
|
assert_equal '<a href="http://google.com">Google</a>', '[url=http://google.com]Google[/url]'.bbcode_to_html
|
98
|
+
assert_equal '<a href="http://google.com"><strong>Bold Google</strong></a>', '[url=http://google.com][b]Bold Google[/b][/url]'.bbcode_to_html
|
86
99
|
assert_equal '<a href="/index.html">Home</a>', '[url=/index.html]Home[/url]'.bbcode_to_html
|
87
100
|
end
|
88
101
|
|
89
102
|
def test_image
|
90
103
|
assert_equal '<img src="http://www.ruby-lang.org/images/logo.gif" alt="" />',
|
91
|
-
|
104
|
+
'[img]http://www.ruby-lang.org/images/logo.gif[/img]'.bbcode_to_html
|
92
105
|
assert_equal '<img src="http://www.ruby-lang.org/images/logo.gif" width="95" height="96" alt="" />',
|
93
|
-
|
106
|
+
'[img=95x96]http://www.ruby-lang.org/images/logo.gif[/img]'.bbcode_to_html
|
94
107
|
assert_equal '<img src="http://www.ruby-lang.org/images/logo.gif" width="123" height="456" alt="" />',
|
95
|
-
|
108
|
+
'[img width=123 height=456]http://www.ruby-lang.org/images/logo.gif[/img]'.bbcode_to_html
|
96
109
|
end
|
97
110
|
|
98
111
|
def test_youtube
|
99
112
|
assert_equal '<iframe id="player" type="text/html" width="400" height="320" src="http://www.youtube.com/embed/E4Fbk52Mk1w?enablejsapi=1" frameborder="0"></iframe>',
|
100
|
-
|
113
|
+
'[youtube]E4Fbk52Mk1w[/youtube]'.bbcode_to_html
|
101
114
|
assert_equal '<iframe id="player" type="text/html" width="640" height="480" src="http://www.youtube.com/embed/E4Fbk52Mk1w?enablejsapi=1" frameborder="0"></iframe>',
|
102
|
-
|
115
|
+
'[youtube width=640 height=480]E4Fbk52Mk1w[/youtube]'.bbcode_to_html
|
103
116
|
end
|
104
117
|
|
105
118
|
def test_youtube_with_full_url
|
106
|
-
full_url =
|
119
|
+
full_url = 'http://www.youtube.com/watch?feature=player_embedded&v=E4Fbk52Mk1w'
|
107
120
|
assert_equal '<iframe id="player" type="text/html" width="400" height="320" src="http://www.youtube.com/embed/E4Fbk52Mk1w?enablejsapi=1" frameborder="0"></iframe>',
|
108
|
-
|
121
|
+
"[youtube]#{full_url}[/youtube]".bbcode_to_html
|
109
122
|
end
|
110
123
|
|
111
124
|
def test_youtube_with_url_shortener
|
112
|
-
full_url =
|
125
|
+
full_url = 'http://www.youtu.be/cSohjlYQI2A'
|
113
126
|
assert_equal '<iframe id="player" type="text/html" width="400" height="320" src="http://www.youtube.com/embed/cSohjlYQI2A?enablejsapi=1" frameborder="0"></iframe>',
|
114
|
-
|
127
|
+
"[youtube]#{full_url}[/youtube]".bbcode_to_html
|
115
128
|
end
|
116
129
|
|
117
130
|
def test_html_escaping
|
@@ -126,49 +139,51 @@ class RubyBbcodeHtmlTest < Minitest::Test
|
|
126
139
|
def test_uri_escaping
|
127
140
|
# There is no tag available, so create our own to test URI escaping
|
128
141
|
escape_param_def = {
|
129
|
-
:
|
130
|
-
:
|
131
|
-
:
|
132
|
-
:
|
142
|
+
escapequery: {
|
143
|
+
html_open: '<a href="%query%">%between%', html_close: '</a>',
|
144
|
+
require_between: true, allow_quick_param: false, allow_between_as_param: true,
|
145
|
+
param_tokens: [{ token: :query, uri_escape: true }]
|
146
|
+
}
|
133
147
|
}
|
134
148
|
assert_equal '<a href="Escaped+string+%28to+be+used+as+URL+%26+more%29">Escaped string (to be used as URL & more)</a>',
|
135
|
-
|
149
|
+
'[escapequery]Escaped string (to be used as URL & more)[/escapequery]'.bbcode_to_html(true, escape_param_def)
|
136
150
|
assert_equal '<a href="http%3A%3A%2Fwww.text.com%2Fpage.php%3Fparam1%3D1%26param2%3D2">http::/www.text.com/page.php?param1=1¶m2=2</a>',
|
137
|
-
|
151
|
+
'[escapequery]http::/www.text.com/page.php?param1=1¶m2=2[/escapequery]'.bbcode_to_html(true, escape_param_def)
|
138
152
|
end
|
139
153
|
|
140
154
|
def test_disable_tags
|
141
|
-
assert_equal
|
142
|
-
assert_equal
|
143
|
-
assert_equal
|
155
|
+
assert_equal '[b]foobar[/b]', '[b]foobar[/b]'.bbcode_to_html(true, {}, :disable, :b)
|
156
|
+
assert_equal '[b]<em>foobar</em>[/b]', '[b][i]foobar[/i][/b]'.bbcode_to_html(true, {}, :disable, :b)
|
157
|
+
assert_equal '[b][i]foobar[/i][/b]', '[b][i]foobar[/i][/b]'.bbcode_to_html(true, {}, :disable, :b, :i)
|
144
158
|
end
|
145
159
|
|
146
160
|
def test_enable_tags
|
147
|
-
assert_equal
|
148
|
-
assert_equal
|
149
|
-
assert_equal
|
161
|
+
assert_equal '<strong>foobar</strong>', '[b]foobar[/b]'.bbcode_to_html(true, {}, :enable, :b)
|
162
|
+
assert_equal '<strong>[i]foobar[/i]</strong>', '[b][i]foobar[/i][/b]'.bbcode_to_html(true, {}, :enable, :b)
|
163
|
+
assert_equal '<strong><em>foobar</em></strong>', '[b][i]foobar[/i][/b]'.bbcode_to_html(true, {}, :enable, :b, :i)
|
150
164
|
end
|
151
165
|
|
152
166
|
def test_to_html_bang_method
|
153
|
-
foo =
|
154
|
-
assert_equal
|
155
|
-
assert_equal
|
167
|
+
foo = '[b]foobar[/b]'
|
168
|
+
assert_equal '<strong>foobar</strong>', foo.bbcode_to_html!
|
169
|
+
assert_equal '<strong>foobar</strong>', foo
|
156
170
|
end
|
157
171
|
|
158
172
|
def test_addition_of_tags
|
159
173
|
mydef = {
|
160
|
-
:
|
161
|
-
:
|
162
|
-
:
|
163
|
-
:
|
174
|
+
test: {
|
175
|
+
html_open: '<test>', html_close: '</test>',
|
176
|
+
description: 'This is a test',
|
177
|
+
example: '[test]Test here[/test]'
|
178
|
+
}
|
164
179
|
}
|
165
180
|
assert_equal 'pre <test>Test here</test> post', 'pre [test]Test here[/test] post'.bbcode_to_html(true, mydef)
|
166
181
|
assert_equal 'pre <strong><test>Test here</test></strong> post', 'pre [b][test]Test here[/test][/b] post'.bbcode_to_html(true, mydef)
|
167
182
|
end
|
168
183
|
|
169
184
|
def test_multiple_tag_test
|
170
|
-
assert_equal
|
171
|
-
|
185
|
+
assert_equal '<strong>bold</strong><em>italic</em><u>underline</u><div class="quote">quote</div><a href="https://test.com">link</a>',
|
186
|
+
'[b]bold[/b][i]italic[/i][u]underline[/u][quote]quote[/quote][url=https://test.com]link[/url]'.bbcode_to_html
|
172
187
|
end
|
173
188
|
|
174
189
|
def test_no_xss_hax
|
@@ -177,8 +192,8 @@ class RubyBbcodeHtmlTest < Minitest::Test
|
|
177
192
|
end
|
178
193
|
|
179
194
|
def test_media_tag
|
180
|
-
input1 =
|
181
|
-
input2 =
|
195
|
+
input1 = '[media]http://www.youtube.com/watch?v=cSohjlYQI2A[/media]'
|
196
|
+
input2 = '[media]http://vimeo.com/46141955[/media]'
|
182
197
|
|
183
198
|
output1 = '<iframe id="player" type="text/html" width="400" height="320" src="http://www.youtube.com/embed/cSohjlYQI2A?enablejsapi=1" frameborder="0"></iframe>'
|
184
199
|
output2 = '<iframe src="http://player.vimeo.com/video/46141955?badge=0" width="400" height="320" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>'
|
@@ -188,15 +203,28 @@ class RubyBbcodeHtmlTest < Minitest::Test
|
|
188
203
|
end
|
189
204
|
|
190
205
|
def test_vimeo_tag
|
191
|
-
input =
|
192
|
-
input2 =
|
206
|
+
input = '[vimeo]http://vimeo.com/46141955[/vimeo]'
|
207
|
+
input2 = '[vimeo]46141955[/vimeo]'
|
193
208
|
output = '<iframe src="http://player.vimeo.com/video/46141955?badge=0" width="400" height="320" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>'
|
194
209
|
|
195
210
|
assert_equal output, input.bbcode_to_html
|
196
211
|
assert_equal output, input2.bbcode_to_html
|
197
212
|
|
198
213
|
assert_equal '<iframe src="http://player.vimeo.com/video/46141955?badge=0" width="640" height="480" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>',
|
199
|
-
|
214
|
+
'[vimeo width=640 height=480]46141955[/vimeo]'.bbcode_to_html
|
215
|
+
end
|
216
|
+
|
217
|
+
def test_unknown_tag
|
218
|
+
RubyBBCode.configuration.ignore_unknown_tags = :exception
|
219
|
+
assert_raises RuntimeError do
|
220
|
+
'[unknown]This is an unknown tag[/unknown]'.bbcode_to_html
|
221
|
+
end
|
222
|
+
|
223
|
+
RubyBBCode.configuration.ignore_unknown_tags = :ignore
|
224
|
+
assert_equal 'This is an unknown tag', '[unknown]This is an unknown tag[/unknown]'.bbcode_to_html
|
225
|
+
|
226
|
+
RubyBBCode.configuration.ignore_unknown_tags = :text
|
227
|
+
assert_equal '[unknown]This is an unknown tag[/unknown]', '[unknown]This is an unknown tag[/unknown]'.bbcode_to_html
|
200
228
|
end
|
201
229
|
|
202
230
|
def test_raised_exceptions
|