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