r111367 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111366‎ | r111367 | r111368 >
Date:13:54, 13 February 2012
Author:gwicke
Status:deferred
Tags:
Comment:
Prefix all internal data- attributes with data-mw- and adjust the whitelist
and test output normalization accordingly. 235 tests passing.
Modified paths:
  • /trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt (modified) (history)
  • /trunk/extensions/VisualEditor/tests/parser/parserTests-whitelist.js (modified) (history)
  • /trunk/extensions/VisualEditor/tests/parser/parserTests.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/tests/parser/parserTests-whitelist.js
@@ -8,12 +8,12 @@
99 // formatting is identical
1010 testWhiteList["Italics and bold"] = "<ul><li> plain</li><li> plain<i>italic</i>plain</li><li> plain<i>italic</i>plain<i>italic</i>plain</li><li> plain<b>bold</b>plain</li><li> plain<b>bold</b>plain<b>bold</b>plain</li><li> plain<i>italic</i>plain<b>bold</b>plain</li><li> plain<b>bold</b>plain<i>italic</i>plain</li><li> plain<i>italic<b>bold-italic</b>italic</i>plain</li><li> plain<b>bold<i>bold-italic</i>bold</b>plain</li><li> plain<i><b>bold-italic</b>italic</i>plain</li><li> plain<i><b>bold-italic</b></i><b>bold</b>plain</li><li> plain<i>italic<b>bold-italic</b></i>plain</li><li> plain<b>bold<i>bold-italic</i></b>plain</li><li> plain l'<i>italic</i>plain</li><li> plain l'<b>bold</b> plain</li></ul>";
1111
12 -testWhiteList["Bug 2702: Mismatched <i>, <b> and <a> tags are invalid"] = "<p><i><a href=\"http://example.com\">text</a></i><a href=\"http://example.com\" data-sourcePos=\"30:61\"><b>text</b></a><i data-sourcePos=\"62:106\">Something <a href=\"http://example.com\">in italic</a></i><i data-sourcePos=\"107:164\">Something <a href=\"http://example.com\">mixed</a></i><a href=\"http://example.com\"><b>, even bold</b></a><i data-sourcePos=\"165:204\"><b data-sourcePos=\"165:204\">Now <a href=\"http://example.com\">both</a></b></i></p>";
 12+testWhiteList["Bug 2702: Mismatched <i>, <b> and <a> tags are invalid"] = "<p><i><a href=\"http://example.com\">text</a></i><a href=\"http://example.com\" data-mw-sourcePos=\"30:61\"><b>text</b></a><i data-mw-sourcePos=\"62:106\">Something <a href=\"http://example.com\">in italic</a></i><i data-mw-sourcePos=\"107:164\">Something <a href=\"http://example.com\">mixed</a></i><a href=\"http://example.com\"><b>, even bold</b></a><i data-mw-sourcePos=\"165:204\"><b data-mw-sourcePos=\"165:204\">Now <a href=\"http://example.com\">both</a></b></i></p>";
1313
14 -testWhiteList["Unclosed and unmatched quotes"] = "<p data-sourcePos=\"0:66\"><i><b>Bold italic text </b>with bold deactivated<b> in between.</b></i></p><p><i><b>Bold italic text </b></i><b>with italic deactivated<i> in between.</i></b></p><p><b>Bold text..</b></p><p>..spanning two paragraphs (should not work).<b></b></p><p><b>Bold tag left open</b></p><p><i>Italic tag left open</i></p><p>Normal text.<!-- Unmatching number of opening, closing tags: -->\n</p><p><b>This year'</b>s election <i>should</i> beat <b>last year'</b>s.</p><p><i>Tom<b>s car is bigger than </b></i><b>Susan</b>s.</p>";
 14+testWhiteList["Unclosed and unmatched quotes"] = "<p data-mw-sourcePos=\"0:66\"><i><b>Bold italic text </b>with bold deactivated<b> in between.</b></i></p><p><i><b>Bold italic text </b></i><b>with italic deactivated<i> in between.</i></b></p><p><b>Bold text..</b></p><p>..spanning two paragraphs (should not work).<b></b></p><p><b>Bold tag left open</b></p><p><i>Italic tag left open</i></p><p>Normal text.<!-- Unmatching number of opening, closing tags: -->\n</p><p><b>This year'</b>s election <i>should</i> beat <b>last year'</b>s.</p><p><i>Tom<b>s car is bigger than </b></i><b>Susan</b>s.</p>";
1515
1616 // The expected result for this test is really broken html.
17 -testWhiteList["Link containing double-single-quotes '' in text embedded in italics (bug 4598 sanity check)"] = "<p data-sourcePos=\"0:45\"><i>Some <a data-type=\"internal\" href=\"Link\">pretty </a></i><a data-type=\"internal\" href=\"Link\">italics<i> and stuff</i></a><i>!</i></p>";
 17+testWhiteList["Link containing double-single-quotes '' in text embedded in italics (bug 4598 sanity check)"] = "<p data-mw-sourcePos=\"0:45\"><i>Some <a data-mw-type=\"internal\" href=\"Link\">pretty </a></i><a data-mw-type=\"internal\" href=\"Link\">italics<i> and stuff</i></a><i>!</i></p>";
1818
1919 testWhiteList["External link containing double-single-quotes in text embedded in italics (bug 4598 sanity check)"] = "<p><i>Some <a href=\"http://example.com/\">pretty </a></i><a href=\"http://example.com/\">italics<i> and stuff</i></a><i>!</i></p>";
2020
@@ -22,13 +22,13 @@
2323
2424 // The comment in the test already suggests this result as correct, but
2525 // supplies the old result without preformatting.
26 -testWhiteList["Bug 6200: Preformatted in <blockquote>"] = "<blockquote data-sourcePos=\"0:12\"><pre>\nBlah</pre></blockquote>";
 26+testWhiteList["Bug 6200: Preformatted in <blockquote>"] = "<blockquote data-mw-sourcePos=\"0:12\"><pre>\nBlah</pre></blockquote>";
2727
2828
2929 // empty table tags / with only a caption are legal in HTML5.
3030 testWhiteList["A table with no data."] = "<table></table>";
3131 testWhiteList["A table with nothing but a caption"] = "<table><caption> caption</caption></table>";
32 -testWhiteList["Fuzz testing: Parser22"] = "<p data-sourcePos=\"0:23\"><a href=\"http://===r:::https://b\">http://===r:::https://b</a></p><table></table>";
 32+testWhiteList["Fuzz testing: Parser22"] = "<p data-mw-sourcePos=\"0:23\"><a href=\"http://===r:::https://b\">http://===r:::https://b</a></p><table></table>";
3333
3434 // MediaWiki changes the order of attributes in tables, ignore that
3535 testWhiteList["Multiplication table"] = "<table border=\"1\" cellpadding=\"2\"><caption>Multiplication table</caption><tbody><tr><th> × </th><th> 1 </th><th> 2 </th><th> 3</th></tr><tr><th> 1</th><td> 1 </td><td> 2 </td><td> 3</td></tr><tr><th> 2</th><td> 2 </td><td> 4 </td><td> 6</td></tr><tr><th> 3</th><td> 3 </td><td> 6 </td><td> 9</td></tr><tr><th> 4</th><td> 4 </td><td> 8 </td><td> 12</td></tr><tr><th> 5</th><td> 5 </td><td> 10 </td><td> 15</td></tr></tbody></table>";
@@ -37,7 +37,7 @@
3838
3939 // Very minor whitespace difference at end of cell (MediaWiki inserts a
4040 // newline before the close tag even if there was no trailing space in the cell)
41 -testWhiteList["Table rowspan"] = "<table border=\"1\" data-sourcePos=\"0:121\"><tbody><tr><td> Cell 1, row 1 </td><td rowspan=\"2\"> Cell 2, row 1 (and 2) </td><td> Cell 3, row 1 </td></tr><tr><td> Cell 1, row 2 </td><td> Cell 3, row 2 </td></tr></tbody></table>";
 41+testWhiteList["Table rowspan"] = "<table border=\"1\" data-mw-sourcePos=\"0:121\"><tbody><tr><td> Cell 1, row 1 </td><td rowspan=\"2\"> Cell 2, row 1 (and 2) </td><td> Cell 3, row 1 </td></tr><tr><td> Cell 1, row 2 </td><td> Cell 3, row 2 </td></tr></tbody></table>";
4242
4343 // Inter-element whitespace only
4444 testWhiteList["Indented table markup mixed with indented pre content (proposed in bug 6200)"] = " \n\n<table><tbody><tr><td><pre>\nText that should be rendered preformatted\n</pre></td></tr></tbody></table>";
@@ -47,9 +47,9 @@
4848 /* Missing token transform functionality */
4949
5050 // We don't implement percent encoding for URIs yet.
51 -testWhiteList["Link containing double-single-quotes '' (bug 4598)"] = "<p><a data-type=\"internal\" href=\"Lista d''e paise d''o munno\">Lista d''e paise d''o munno</a></p>";
 51+testWhiteList["Link containing double-single-quotes '' (bug 4598)"] = "<p><a data-mw-type=\"internal\" href=\"Lista d''e paise d''o munno\">Lista d''e paise d''o munno</a></p>";
5252
53 -testWhiteList["Link containing \"<#\" and \">#\" as a hex sequences"] = "<p><a data-type=\"internal\" href=\"&lt;%23\">&lt;%23</a><a data-type=\"internal\" href=\"&gt;%23\">&gt;%23</a></p>";
 53+testWhiteList["Link containing \"<#\" and \">#\" as a hex sequences"] = "<p><a data-mw-type=\"internal\" href=\"&lt;%23\">&lt;%23</a><a data-mw-type=\"internal\" href=\"&gt;%23\">&gt;%23</a></p>";
5454
5555
5656 // Sanitizer
@@ -57,14 +57,14 @@
5858 testWhiteList["Table security: embedded pipes (http://lists.wikimedia.org/mailman/htdig/wikitech-l/2006-April/022293.html)"] = "<table><tbody><tr><td> |<a href=\"ftp://|x||\">[1]</a>\" onmouseover=\"alert(document.cookie)\"&gt;test</td></tr></tbody></table>";
5959
6060 // Sanitizer, but UTF8 in link might actually be ok in HTML5
61 -testWhiteList["External link containing double-single-quotes with no space separating the url from text in italics"] = "<p><a href=\"http://www.musee-picasso.fr/pages/page_id18528_u1l2.htm\"><i>La muerte de Casagemas</i> (1901) en el sitio de </a><a data-type=\"internal\" href=\"Museo Picasso (París)\">Museo Picasso</a>.</p>";
 61+testWhiteList["External link containing double-single-quotes with no space separating the url from text in italics"] = "<p><a href=\"http://www.musee-picasso.fr/pages/page_id18528_u1l2.htm\"><i>La muerte de Casagemas</i> (1901) en el sitio de </a><a data-mw-type=\"internal\" href=\"Museo Picasso (París)\">Museo Picasso</a>.</p>";
6262
6363 // plain percent sign is also valid in HTML5
64 -testWhiteList["Bug 4781, 5267: %28, %29 in URL"] = "<p><a href=\"http://www.example.com/?title=Ben-Hur_(1959_film)\" data-sourcePos=\"0:53\">http://www.example.com/?title=Ben-Hur_(1959_film)</a></p>";
 64+testWhiteList["Bug 4781, 5267: %28, %29 in URL"] = "<p><a href=\"http://www.example.com/?title=Ben-Hur_(1959_film)\" data-mw-sourcePos=\"0:53\">http://www.example.com/?title=Ben-Hur_(1959_film)</a></p>";
6565
66 -testWhiteList["External links: wiki links within external link (Bug 3695)"] = "<p><a href=\"http://example.com\" data-type=\"external\" data-sourcePos=\"0:54\"></a><a data-type=\"internal\" href=\"wikilink\">wikilink</a> embedded in ext link</p>";
 66+testWhiteList["External links: wiki links within external link (Bug 3695)"] = "<p><a href=\"http://example.com\" data-mw-type=\"external\" data-mw-sourcePos=\"0:54\"></a><a data-mw-type=\"internal\" href=\"wikilink\">wikilink</a> embedded in ext link</p>";
6767
68 -testWhiteList["Bug 4781, 5267: %25 in URL"] = "<p><a href=\"http://www.example.com/?title=100%_Bran\" data-sourcePos=\"0:41\">http://www.example.com/?title=100%_Bran</a></p>";
 68+testWhiteList["Bug 4781, 5267: %25 in URL"] = "<p><a href=\"http://www.example.com/?title=100%_Bran\" data-mw-sourcePos=\"0:41\">http://www.example.com/?title=100%_Bran</a></p>";
6969
7070
7171 if (typeof module == "object") {
Index: trunk/extensions/VisualEditor/tests/parser/parserTests.js
@@ -331,7 +331,7 @@
332332 // known-ok differences.
333333 ParserTests.prototype.normalizeOut = function ( out ) {
334334 // TODO: Do not strip newlines in pre and nowiki blocks!
335 - return out.replace(/[\r\n]| data-[a-zA-Z-]+="[^">]*"/g, '')
 335+ return out.replace(/[\r\n]| data-mw-[a-zA-Z-]+="[^">]*"/g, '')
336336 .replace(/<!--.*?-->\n?/gm, '');
337337 };
338338
Index: trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt
@@ -746,7 +746,7 @@
747747 var res = [
748748 new TagTk( 'a', [
749749 new KV('href', target),
750 - new KV('data-type', 'external')
 750+ new KV('data-mw-type', 'external')
751751 ] ),
752752 ].concat( text
753753 , [ new EndTagTk( 'a' )]);
@@ -897,7 +897,7 @@
898898 trail:(! [A-Z \t(),.:-] tc:text_char { return tc })* {
899899 var obj = new TagTk( 'a',
900900 [
901 - new KV('data-type', 'internal')
 901+ new KV('data-mw-type', 'internal')
902902 ] ),
903903 textTokens = [];
904904 obj.attribs.push( new KV('href', target) );

Status & tagging log