4 use Test::More tests => 31;
7 BEGIN { use_ok("IkiWiki"); }
9 # Initialize htmlscrubber plugin
10 %config=IkiWiki::defaultconfig();
11 $config{srcdir}=$config{destdir}="/dev/null";
12 IkiWiki::loadplugins();
13 IkiWiki::checkconfig();
15 is(IkiWiki::htmlize("foo", "foo", "mdwn", "foo\n\nbar\n"), "<p>foo</p>\n\n<p>bar</p>\n",
17 my $val=Encode::encode_utf8(IkiWiki::htmlize("foo", "foo", "mdwn", readfile("t/test1.mdwn")));
18 ok($val =~/ó/ && $val =~/óóóóó/, "utf8; bug #373203");
19 ok(IkiWiki::htmlize("foo", "foo", "mdwn", readfile("t/test2.mdwn")),
20 "this file crashes markdown if it's fed in as decoded utf-8");
23 my $html=IkiWiki::htmlize("foo", "foo", "mdwn", shift);
24 return $html =~ /GOTCHA/;
26 ok(!gotcha(q{<a href="javascript:alert('GOTCHA')">click me</a>}),
28 ok(!gotcha(q{<a href="jscript:alert('GOTCHA')">click me</a>}),
30 ok(!gotcha(q{<a href="vbscript:alert('GOTCHA')">click me</a>}),
32 ok(!gotcha(q{<a href="java script:alert('GOTCHA')">click me</a>}),
33 "java-tab-script url");
34 ok(!gotcha(q{<span style="any: expressio(GOTCHA)n(window.location='http://example.org/')">foo</span>}),
35 "entity-encoded CSS script test");
36 ok(!gotcha(q{<span style="any: expression(GOTCHA)(window.location='http://example.org/')">foo</span>}),
37 "another entity-encoded CSS script test");
38 ok(!gotcha(q{<script>GOTCHA</script>}),
40 ok(!gotcha(q{<form action="javascript:alert('GOTCHA')">foo</form>}),
41 "form action with javascript");
42 ok(!gotcha(q{<video poster="javascript:alert('GOTCHA')" href="foo.avi">foo</video>}),
43 "video poster with javascript");
44 ok(!gotcha(q{<span style="background: url(javascript:window.location=GOTCHA)">a</span>}),
46 ok(! gotcha(q{<img src="data:text/javascript;GOTCHA">}),
47 "data:text/javascript (jeez!)");
48 ok(gotcha(q{<img src="data:image/png;base64,GOTCHA">}), "data:image/png");
49 ok(gotcha(q{<img src="data:image/gif;base64,GOTCHA">}), "data:image/gif");
50 ok(gotcha(q{<img src="data:image/jpeg;base64,GOTCHA">}), "data:image/jpeg");
51 ok(gotcha(q{<p>javascript:alert('GOTCHA')</p>}),
52 "not javascript AFAIK (but perhaps some web browser would like to
53 be perverse and assume it is?)");
54 ok(gotcha(q{<img src="javascript.png?GOTCHA">}), "not javascript");
55 ok(gotcha(q{<a href="javascript.png?GOTCHA">foo</a>}), "not javascript");
56 is(IkiWiki::htmlize("foo", "foo", "mdwn",
57 q{<img alt="foo" src="foo.gif">}),
58 q{<img alt="foo" src="foo.gif">}, "img with alt tag allowed");
59 is(IkiWiki::htmlize("foo", "foo", "mdwn",
60 q{<a href="http://google.com/">}),
61 q{<a href="http://google.com/">}, "absolute url allowed");
62 is(IkiWiki::htmlize("foo", "foo", "mdwn",
63 q{<a href="foo.html">}),
64 q{<a href="foo.html">}, "relative url allowed");
65 is(IkiWiki::htmlize("foo", "foo", "mdwn",
66 q{<span class="foo">bar</span>}),
67 q{<span class="foo">bar</span>}, "class attribute allowed");
68 is(IkiWiki::htmlize("foo", "foo", "mdwn",
69 q{<a href="aaa#foo">}),
70 q{<a href="aaa#foo">}, "simple anchor allowed");
71 is(IkiWiki::htmlize("foo", "foo", "mdwn",
72 q{<a href="aaa#foo:bar">}),
73 q{<a href="aaa#foo:bar">}, "colon allowed in anchor");
74 is(IkiWiki::htmlize("foo", "foo", "mdwn",
75 q{<a href="aaa?foo:bar">}),
76 q{<a href="aaa?foo:bar">}, "colon allowed in query string");
77 is(IkiWiki::htmlize("foo", "foo", "mdwn",
78 q{<a href="foo:bar">}),
79 q{<a>}, "unknown protocol blocked");
80 is(IkiWiki::htmlize("foo", "foo", "mdwn",
82 q{<a href="#foo">}, "simple relative anchor allowed");
83 is(IkiWiki::htmlize("foo", "foo", "mdwn",
84 q{<a href="#foo:bar">}),
85 q{<a href="#foo:bar">}, "colon in simple relative anchor allowed");