From 60dc05d5279bec6ab83c78c069ab305739456f63 Mon Sep 17 00:00:00 2001 From: r888888888 Date: Wed, 19 Jun 2013 16:40:12 -0700 Subject: [PATCH] revert to old dtext spoiler behavior --- app/logical/d_text.rb | 5 +-- test/unit/dtext_test.rb | 90 +++++++++++++++++++++++++++++++++++------ 2 files changed, 80 insertions(+), 15 deletions(-) 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

", p("[spoiler]this is a spoiler with no closing tag\nnew text")) - assert_equal("

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("
\n

this is a spoiler with no closing tag

\n

new text

\n
", p("[spoiler]this is a spoiler with no closing tag\n\nnew text")) + end + + def test_spoilers_with_no_closing_tag_2 + assert_equal("

this is a spoiler with no closing tag
new text

", p("[spoiler]this is a spoiler with no closing tag\nnew text")) + end + + def test_spoilers_with_no_closing_tag_block assert_equal("

this is a block spoiler with no closing tag

", p("[spoiler]\nthis is a block spoiler with no closing tag")) end + def test_spoilers_nested + assert_equal("
\n

this is

\n

a nested

\n

spoiler

\n
", p("[spoiler]this is [spoiler]a nested[/spoiler] spoiler[/spoiler]")) + end + def test_paragraphs - assert_equal("

a

", p("a")) assert_equal("

abc

", p("abc")) + end + + def test_paragraphs_with_newlines_1 assert_equal("

a
b
c

", p("a\nb\nc")) + end + + def test_paragraphs_with_newlines_2 assert_equal("

a

b

", p("a\n\nb")) end def test_headers assert_equal("

header

", p("h1. header")) - assert_equal("

header

paragraph

", p("h1.header\n\nparagraph")) end def test_quote_blocks assert_equal('

test

', p("[quote]\ntest\n[/quote]")) + end + + def test_quote_blocks_nested assert_equal("
\n

a

\n

b

\n

c

\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 http://test.com b

', p('a http://test.com b')) + end + + def test_urls_with_newline assert_equal('

http://test.com
b

', 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('

test

', 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('', p('* a')) + end + + def test_lists_2 assert_equal('', p("* a\n* b").gsub(/\n/, "")) + end + + def test_lists_nested assert_equal('', p("* a\n** b").gsub(/\n/, "")) + end + + def test_lists_inline assert_equal('', p("* post #1").gsub(/\n/, "")) end - def test_inline + def test_inline_tags assert_equal('

tag

', p("{{tag}}")) + end + + def test_inline_tags_conjunction assert_equal('

tag1 tag2

', p("{{tag1 tag2}}")) + end + + def test_inline_tags_special_entities assert_equal('

<3

', p("{{<3}}")) end @@ -78,8 +141,11 @@ class DTextTest < ActiveSupport::TestCase 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("

2 3 | 5 6

", 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