2007-01-22 07:43:50 -06:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
2009-11-30 16:28:18 -06:00
|
|
|
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
2007-01-22 07:43:50 -06:00
|
|
|
require 'chunks/nowiki'
|
|
|
|
|
|
|
|
class NoWikiTest < Test::Unit::TestCase
|
|
|
|
include ChunkMatch
|
|
|
|
|
|
|
|
def test_simple_nowiki
|
|
|
|
match(NoWiki, 'This sentence contains <nowiki>[[raw text]]</nowiki>. Do not touch!',
|
|
|
|
:plain_text => '[[raw text]]'
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2008-12-20 23:24:50 -06:00
|
|
|
def test_include_nowiki
|
|
|
|
match(NoWiki, 'This sentence contains <nowiki>[[!include foo]]</nowiki>. Do not touch!',
|
|
|
|
:plain_text => '[[!include foo]]'
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2008-05-20 17:02:10 -05:00
|
|
|
def test_markdown_nowiki
|
|
|
|
match(NoWiki, 'This sentence contains <nowiki>*raw text*</nowiki>. Do not touch!',
|
|
|
|
:plain_text => '*raw text*'
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2008-05-21 02:06:31 -05:00
|
|
|
def test_sanitize_nowiki
|
2008-05-20 17:02:10 -05:00
|
|
|
match(NoWiki, 'This sentence contains <nowiki>[[test]]&<a href="a&b">shebang</a> <script>alert("xss!");</script> *foo*</nowiki>. Do not touch!',
|
2009-11-30 16:28:18 -06:00
|
|
|
:plain_text => "[[test]]&<a href='a&b'>shebang</a> <script>alert("xss!");</script> *foo*"
|
2008-05-20 17:02:10 -05:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2008-11-30 21:44:52 -06:00
|
|
|
def test_sanitize_nowiki_ill_formed
|
|
|
|
match(NoWiki, "<nowiki><animateColor xlink:href='#foo'/></nowiki>",
|
2009-11-30 16:28:18 -06:00
|
|
|
:plain_text => "<animateColor xlink:href='#foo'/>"
|
2008-11-30 21:44:52 -06:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2008-12-07 00:24:25 -06:00
|
|
|
def test_sanitize_nowiki_ill_formed_II
|
|
|
|
match(NoWiki, "<nowiki><animateColor xlink:href='#foo'/>\000</nowiki>",
|
2009-11-30 16:28:18 -06:00
|
|
|
:plain_text => %(<animateColor xlink:href='#foo'/>)
|
2008-12-07 00:24:25 -06:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2009-09-26 00:36:28 -05:00
|
|
|
def test_sanitize_nowiki_bad_utf8
|
|
|
|
match(NoWiki, "<nowiki>\357elephant & \302ivory</nowiki>",
|
2009-11-30 16:28:18 -06:00
|
|
|
:plain_text => "".respond_to?(:force_encoding) ? "elephant &AMP; ivory" : "ephant &AMP; vory"
|
2009-09-26 00:36:28 -05:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2007-01-22 07:43:50 -06:00
|
|
|
end
|