diff --git a/app/logical/d_text.rb b/app/logical/d_text.rb
index c34df6e6a..67bfe6298 100644
--- a/app/logical/d_text.rb
+++ b/app/logical/d_text.rb
@@ -19,7 +19,6 @@ class DText
str.gsub!(/\[i\](.+?)\[\/i\]/i, '\1')
str.gsub!(/\[s\](.+?)\[\/s\]/i, '\1')
str.gsub!(/\[u\](.+?)\[\/u\]/i, '\1')
- str.gsub!(/\[spoilers?\](.+?)\[\/spoilers?\]/i, '\1')
str = parse_links(str)
str = parse_aliased_wiki_links(str)
@@ -131,8 +130,8 @@ class DText
str.gsub!(/\s*\[\/quote\]\s*/m, "\n\n[/quote]\n\n")
str.gsub!(/\s*\[code\]\s*/m, "\n\n[code]\n\n")
str.gsub!(/\s*\[\/code\]\s*/m, "\n\n[/code]\n\n")
- str.gsub!(/\[spoilers?\]\s+/m, "\n\n[spoiler]\n\n")
- str.gsub!(/\s+\[\/spoilers?\]/m, "\n\n[/spoiler]\n\n")
+ str.gsub!(/\s*\[spoilers?\](?!\])\s*/m, "\n\n[spoiler]\n\n")
+ str.gsub!(/\s*\[\/spoilers?\]\s*/m, "\n\n[/spoiler]\n\n")
str.gsub!(/^(h[1-6]\.\s*.+)$/, "\n\n\\1\n\n")
str.gsub!(/\s*\[expand(\=[^\]]*)?\]\s*/m, "\n\n[expand\\1]\n\n")
str.gsub!(/\s*\[\/expand\]\s*/m, "\n\n[/expand]\n\n")
diff --git a/test/unit/dtext_test.rb b/test/unit/dtext_test.rb
index a5412ba09..aa6860e6b 100644
--- a/test/unit/dtext_test.rb
+++ b/test/unit/dtext_test.rb
@@ -5,40 +5,71 @@ class DTextTest < ActiveSupport::TestCase
DText.parse(s)
end
- def test_sanitize
+ def test_sanitize_less_than
assert_equal('
<
', p("<")) + end + + def test_sanitize_greater_than assert_equal('>
', p(">")) + end + + def test_sanitize_ampersand assert_equal('&
', p("&")) end def test_wiki_links assert_equal("a b c
", p("a [[b]] c")) + end + + def test_wiki_links_spoiler assert_equal("a spoiler c
", p("a [[spoiler]] c")) end - def test_spoilers - assert_equal("this is an inline spoiler.
", p("this is [spoiler]an inline spoiler[/spoiler].")) + def test_spoilers_inline + assert_equal("this is
an inline spoiler
.
", p("this is [spoiler]an inline spoiler[/spoiler].")) + end + + def test_spoilers_block assert_equal("this is
a block spoiler
.
", p("this is\n\n[spoiler]\na block spoiler\n[/spoiler].")) - assert_equal("[spoiler]this is a spoiler with no closing tag
new text
", p("[spoiler]this is a spoiler with no closing tag\n\nnew text")) - assert_equal("[spoiler]this is a spoiler with no closing tag
new text
this is [spoiler]a nested spoiler[/spoiler]
", p("[spoiler]this is [spoiler]a nested[/spoiler] spoiler[/spoiler]")) + end + + def test_spoilers_with_no_closing_tag_1 + assert_equal("this is a spoiler with no closing tag
\nnew text
\nthis is a spoiler with no closing tag
new text
this is a block spoiler with no closing tag
this is
\na nested
spoiler
\na
", p("a")) assert_equal("abc
", p("abc")) + end + + def test_paragraphs_with_newlines_1 assert_equal("a
b
c
a
b
", p("a\n\nb")) end def test_headers assert_equal("paragraph
", p("h1.header\n\nparagraph")) end def test_quote_blocks assert_equal('', p("[quote]\ntest\n[/quote]")) + end + + def test_quote_blocks_nested assert_equal("test
\n", p("[quote]\na\n[quote]\nb\n[/quote]\nc\n[/quote]")) end @@ -48,29 +79,61 @@ class DTextTest < ActiveSupport::TestCase def test_urls assert_equal('a
\n\nb
c
\n
a http://test.com b
', p('a http://test.com b')) + end + + def test_urls_with_newline assert_equal('', p("http://test.com\nb")) + end + + def test_urls_with_paths assert_equal('a http://test.com/~bob/image.jpg b
', p('a http://test.com/~bob/image.jpg b')) + end + + def test_urls_with_fragment assert_equal('a http://test.com/home.html#toc b
', p('a http://test.com/home.html#toc b')) + end + + def test_auto_urls assert_equal('a http://test.com. b
', p('a http://test.com. b')) + end + + def test_auto_urls_in_parentheses assert_equal('a (http://test.com) b
', p('a (http://test.com) b')) end def test_old_syle_links assert_equal('', p('"test":http://test.com')) - assert_equal('"1" 2
', p('"1" "2":http://two.com')) + end + + def test_old_style_links_with_special_entities assert_equal('"1" 2 & 3
', p('"1" "2 & 3":http://three.com')) end - def test_lists + def test_lists_1 assert_equal('a
b
', p("a\n\n\n\n\n\n\nb\n\n\n\n")) end - def test_complex_links + def test_complex_links_1 assert_equal("", p("[[1|2 3]] | [[4|5 6]]")) + end + + def test_complex_links_2 assert_equal("Tags (Tagging Guidelines | Tag Checklist | Tag Groups)
", p("Tags [b]([[howto:tag|Tagging Guidelines]] | [[howto:tag_checklist|Tag Checklist]] | [[Tag Groups]])[/b]")) end end