Arlolra has uploaded a new change for review.
https://gerrit.wikimedia.org/r/235277
Change subject: Tabs are preventing nowiki pre protection
......................................................................
Tabs are preventing nowiki pre protection
* The regexp wants spaces followed immediately by non-whitespace chars,
when it should really be anywhere on the line.
* The changes to the "1. Leading whitespace in SOL context should be
escaped" test are because leading tabs don't need escaping.
Change-Id: I1461a0e155477f57d9b1835b4e662c1ee85ba699
---
M lib/wts.escapeWikitext.js
M tests/parserTests-blacklist.js
M tests/parserTests.txt
3 files changed, 46 insertions(+), 17 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid
refs/changes/77/235277/1
diff --git a/lib/wts.escapeWikitext.js b/lib/wts.escapeWikitext.js
index c824cc5..0f18fc6 100644
--- a/lib/wts.escapeWikitext.js
+++ b/lib/wts.escapeWikitext.js
@@ -565,7 +565,7 @@
var sol = state.onSOL && !indentPreSafeMode;
if (!fullCheckNeeded) {
hasQuoteChar = /'/.test(text);
- indentPreUnsafe = (!indentPreSafeMode && (/\n
+[^\s]+/).test(text) || sol && (/^ +[^\s]+/).test(text));
+ indentPreUnsafe = (!indentPreSafeMode && (/\n
+[^\r\n]*?[^\s]+/).test(text) || sol && (/^ +[^\r\n]*?[^\s]+/).test(text));
hasNonQuoteEscapableChars =
/[<>\[\]\-\+\|!=#\*:;~{}]|__[^_]*__/.test(text);
}
diff --git a/tests/parserTests-blacklist.js b/tests/parserTests-blacklist.js
index 291f296..67ffe5c 100644
--- a/tests/parserTests-blacklist.js
+++ b/tests/parserTests-blacklist.js
@@ -305,7 +305,6 @@
add("wt2html", "Special parser function", "<p
data-parsoid='{\"dsr\":[0,65,0,0]}'><span about=\"#mwt1\"
typeof=\"mw:Transclusion\"
data-parsoid='{\"pi\":[[]],\"dsr\":[0,23,null,null]}'
data-mw='{\"parts\":[{\"template\":{\"target\":{\"wt\":\"#special:RandomPage\",\"function\":\"#special\"},\"params\":{},\"i\":0}}]}'>Parser
function implementation for pf_#special missing in Parsoid.</span>\n<span
about=\"#mwt2\" typeof=\"mw:Transclusion\"
data-parsoid='{\"pi\":[[]],\"dsr\":[24,45,null,null]}'
data-mw='{\"parts\":[{\"template\":{\"target\":{\"wt\":\"#special:BaDtItLe\",\"function\":\"#special\"},\"params\":{},\"i\":0}}]}'>Parser
function implementation for pf_#special missing in Parsoid.</span>\n<span
about=\"#mwt3\" typeof=\"mw:Transclusion\"
data-parsoid='{\"pi\":[[]],\"dsr\":[46,65,null,null]}'
data-mw='{\"parts\":[{\"template\":{\"target\":{\"wt\":\"#special:Foobar\",\"function\":\"#special\"},\"params\":{},\"i\":0}}]}'>Parser
function implementation for pf_#special missing in Parsoid.</span></p>");
add("wt2html", "1. SOL-sensitive wikitext tokens as template-args", "<p
data-parsoid='{\"dsr\":[0,35,0,0]}'><span about=\"#mwt1\"
typeof=\"mw:Transclusion\"
data-parsoid='{\"pi\":[[{\"k\":\"1\",\"spc\":[\"\",\"\",\"\",\"\"]}]],\"dsr\":[0,11,null,null]}'
data-mw='{\"parts\":[{\"template\":{\"target\":{\"wt\":\"echo\",\"href\":\"./Template:Echo\"},\"params\":{\"1\":{\"wt\":\"*a\"}},\"i\":0}}]}'>*a</span>\n<span
about=\"#mwt2\" typeof=\"mw:Transclusion\"
data-parsoid='{\"pi\":[[{\"k\":\"1\",\"spc\":[\"\",\"\",\"\",\"\"]}]],\"dsr\":[12,23,null,null]}'
data-mw='{\"parts\":[{\"template\":{\"target\":{\"wt\":\"echo\",\"href\":\"./Template:Echo\"},\"params\":{\"1\":{\"wt\":\"#a\"}},\"i\":0}}]}'>#a</span>\n<span
about=\"#mwt3\" typeof=\"mw:Transclusion\"
data-parsoid='{\"pi\":[[{\"k\":\"1\",\"spc\":[\"\",\"\",\"\",\"\"]}]],\"dsr\":[24,35,null,null]}'
data-mw='{\"parts\":[{\"template\":{\"target\":{\"wt\":\"echo\",\"href\":\"./Template:Echo\"},\"params\":{\"1\":{\"wt\":\":a\"}},\"i\":0}}]}'>:a</span></p>");
add("wt2html", "Links 3. WikiLinks: No escapes needed", "<p
data-parsoid='{\"dsr\":[0,31,0,0]}'>[[Foo|[Foobar]]\n<a rel=\"mw:WikiLink\"
href=\"./Foo\" title=\"Foo\"
data-parsoid='{\"stx\":\"piped\",\"a\":{\"href\":\"./Foo\"},\"sa\":{\"href\":\"Foo\"},\"dsr\":[16,31,6,2]}'>foo|bar</a></p>");
-add("wt2html", "1. Leading whitespace in SOL context should be escaped", "<p
data-parsoid='{\"dsr\":[0,19,0,0]}'><span typeof=\"mw:Nowiki\"
data-parsoid='{\"dsr\":[0,18,8,9]}'> </span>a</p>\n\n<p
data-parsoid='{\"dsr\":[21,41,0,0]}'><span typeof=\"mw:Nowiki\"
data-parsoid='{\"dsr\":[21,39,8,9]}'> </span> a</p>\n\n<p
data-parsoid='{\"dsr\":[43,67,0,0]}'><span typeof=\"mw:Nowiki\"
data-parsoid='{\"dsr\":[43,61,8,9]}'>\t</span>a(tab)</p>\n\n<p
data-parsoid='{\"dsr\":[69,121,0,0]}'><span typeof=\"mw:Nowiki\"
data-parsoid='{\"dsr\":[69,87,8,9]}'> </span>\ta\n<!--cmt-->\n<span
typeof=\"mw:Nowiki\" data-parsoid='{\"dsr\":[101,119,8,9]}'> </span>
a</p>\n\n<p data-parsoid='{\"dsr\":[123,144,0,0]}'>a\n<span
typeof=\"mw:Nowiki\" data-parsoid='{\"dsr\":[125,143,8,9]}'> </span>b</p>\n\n<p
data-parsoid='{\"dsr\":[146,167,0,0]}'>a\n<span typeof=\"mw:Nowiki\"
data-parsoid='{\"dsr\":[148,166,8,9]}'>\t</span>b</p>\n\n<p
data-parsoid='{\"dsr\":[169,191,0,0]}'>a\n<span typeof=\"mw:Nowiki\"
data-parsoid='{\"dsr\":[171,189,8,9]}'>\t</span> b</p>");
add("wt2html", "1. a tags", "<p data-parsoid='{\"dsr\":[0,38,0,0]}'><a
href=\"http://google.com\">google</a></p>");
add("wt2html", "Parsoid-only: Don't wrap broken template tags in <nowiki> on
wt2wt (Bug 42353)", "<p data-parsoid='{\"dsr\":[0,4,0,0]}'><span
typeof=\"mw:Nowiki\"
data-parsoid='{\"src\":\"{{}}\",\"dsr\":[0,4,0,0]}'>{{}}</span></p>");
add("wt2html", "Parsoid-only: Don't wrap broken template tags in <nowiki> on
wt2wt (Bug 42353)", "<p data-parsoid='{\"dsr\":[0,4,0,0]}'><span
typeof=\"mw:Nowiki\"
data-parsoid='{\"src\":\"}}{{\",\"dsr\":[0,4,0,0]}'>}}{{</span></p>");
@@ -673,7 +672,6 @@
add("html2html", "Entities in ref name", "<p
data-parsoid='{\"dsr\":[0,38,0,0]}'><span about=\"#mwt2\" class=\"mw-ref\"
id=\"cite_ref-test_.26amp.3B_me_1-0\" rel=\"dc:references\"
typeof=\"mw:Extension/ref\" data-parsoid='{\"dsr\":[0,38,30,6]}'
data-mw='{\"name\":\"ref\",\"body\":{\"id\":\"mw-reference-text-cite_note-test_.26amp.3B_me-1\"},\"attrs\":{\"name\":\"test
&amp;amp; me\"}}'><a href=\"#cite_note-test_.26amp.3B_me-1\"
style=\"counter-reset: mw-Ref 1;\"><span
class=\"mw-reflink-text\">[1]</span></a></span></p>\n<ol
class=\"mw-references\" typeof=\"mw:Extension/references\" about=\"#mwt4\"
data-parsoid='{\"dsr\":[39,53,2,2]}'
data-mw='{\"name\":\"references\",\"attrs\":{}}'><li
about=\"#cite_note-test_.26amp.3B_me-1\"
id=\"cite_note-test_.26amp.3B_me-1\"><a
href=\"#cite_ref-test_.26amp.3B_me_1-0\" rel=\"mw:referencedBy\"><span
class=\"mw-linkback-text\">↑ </span></a> <span
id=\"mw-reference-text-cite_note-test_.26amp.3B_me-1\"
class=\"mw-reference-text\" data-parsoid=\"{}\">hi</span></li></ol>");
add("html2html", "Empty LI and TR nodes should not be stripped from top-level
content", "<ul data-parsoid='{\"dsr\":[0,9,0,0]}'><li
data-parsoid='{\"dsr\":[0,3,1,0]}'> a</li>\n<li
data-parsoid='{\"dsr\":[4,5,1,0]}'></li>\n<li
data-parsoid='{\"dsr\":[6,9,1,0]}'> b</li></ul>\n\n<table
data-parsoid='{\"dsr\":[11,26,2,2]}'>\n\n<tbody
data-parsoid='{\"dsr\":[15,24,0,0]}'><tr
data-parsoid='{\"startTagSrc\":\"|-\",\"autoInsertedEnd\":true,\"dsr\":[15,22,2,0]}'>\n<td
data-parsoid='{\"autoInsertedEnd\":true,\"dsr\":[18,22,1,0]}'>foo</td></tr>\n\n</tbody></table>\n");
add("html2html", "Links 3. WikiLinks: No escapes needed", "<p
data-parsoid='{\"dsr\":[0,31,0,0]}'>[[Foo|[Foobar]]\n<a rel=\"mw:WikiLink\"
href=\"./Foo\" title=\"Foo\"
data-parsoid='{\"stx\":\"piped\",\"a\":{\"href\":\"./Foo\"},\"sa\":{\"href\":\"Foo\"},\"dsr\":[16,31,6,2]}'>foo|bar</a></p>\n");
-add("html2html", "1. Leading whitespace in SOL context should be escaped", "<p
data-parsoid='{\"dsr\":[0,19,0,0]}'><span typeof=\"mw:Nowiki\"
data-parsoid='{\"dsr\":[0,18,8,9]}'> </span>a</p>\n\n<p
data-parsoid='{\"dsr\":[21,41,0,0]}'><span typeof=\"mw:Nowiki\"
data-parsoid='{\"dsr\":[21,39,8,9]}'> </span> a</p>\n\n<p
data-parsoid='{\"dsr\":[43,50,0,0]}'>\ta(tab)</p>\n\n<pre
data-parsoid='{\"dsr\":[52,55,1,0]}'>\ta</pre>\n\n<!--cmt--><p
data-parsoid='{\"dsr\":[67,87,0,0]}'><span typeof=\"mw:Nowiki\"
data-parsoid='{\"dsr\":[67,85,8,9]}'> </span> a</p>\n\n<p
data-parsoid='{\"dsr\":[89,110,0,0]}'>a\n<span typeof=\"mw:Nowiki\"
data-parsoid='{\"dsr\":[91,109,8,9]}'> </span>b</p>\n\n<p
data-parsoid='{\"dsr\":[112,116,0,0]}'>a\n\tb</p>\n\n<p
data-parsoid='{\"dsr\":[118,123,0,0]}'>a\n\t b</p>\n");
add("html2html", "1. a tags", "<p data-parsoid='{\"dsr\":[0,38,0,0]}'><a
href=\"http://google.com\">google</a></p>");
add("html2html", "Parsoid-only: Don't wrap broken template tags in <nowiki> on
wt2wt (Bug 42353)", "<p data-parsoid='{\"dsr\":[0,21,0,0]}'><span
typeof=\"mw:Nowiki\" data-parsoid='{\"dsr\":[0,21,8,9]}'>{{}}</span></p>");
add("html2html", "Parsoid-only: Don't wrap broken template tags in <nowiki> on
wt2wt (Bug 42353)", "<p data-parsoid='{\"dsr\":[0,21,0,0]}'><span
typeof=\"mw:Nowiki\" data-parsoid='{\"dsr\":[0,21,8,9]}'>}}{{</span></p>");
@@ -715,7 +713,6 @@
add("html2wt", "Block tag on both lines (<blockquote>)",
"a\n<blockquote>\nfoo\n</blockquote>\nb\n<blockquote>\nfoo\n</blockquote>");
add("html2wt", "Multiple lines without block tags", "<div>foo</div>\na\n\nb c
d e\n\nx\n<div>foo</div>\nz\n");
add("html2wt", "Preformatted text", " This is some\n Preformatted text\n With
''italic''\n And '''bold'''\n And a [[wiki/Main Page|link]]\n");
-add("html2wt", "Tabs don't trigger preformatted text", "\tThis is not\n\t
preformatted text.\n\n This is preformatted text.\n \tSo is this.\n");
add("html2wt", "<pre> with <nowiki> inside (compatibility with 1.6 and
earlier)", " <nowiki><b>\n <cite>\n <em></nowiki>\n");
add("html2wt", "Regression with preformatted in <center>", "<center>\n
Blah\n\n</center>\n");
add("html2wt", "Bug 52763: Preformatted in <blockquote>", "<blockquote>\n
Blah\n\n{|\n\n|\n indented cell (no pre-wrapping!)\n\n|}\n</blockquote>\n");
@@ -1397,7 +1394,6 @@
add("html2wt", "Lists: 3. Only bullets at start of text should be escaped", "*
<nowiki>*foo*bar</nowiki>\n\n* <nowiki>*foo</nowiki>''it''*bar\n");
add("html2wt", "Lists: 4. No escapes needed", "* foo*bar\n\n* ''foo''*bar\n\n*
[[Foo]]: bar\n\n* [[Foo]]*bar\n");
add("html2wt", "HRs: 1. Single line",
"----\n<nowiki>----</nowiki>\n----\n<nowiki>=foo=</nowiki>\n----\n<nowiki>*</nowiki>foo\n");
-add("html2wt", "1. Leading whitespace in SOL context should be escaped",
"<nowiki> </nowiki>a\n\n<nowiki> </nowiki> a\n\n\ta(tab)\n\n
\ta\n\n<!--cmt--><nowiki> </nowiki> a\n\na\n<nowiki>
</nowiki>b\n\na\n\tb\n\na\n\t b\n");
add("html2wt", "3. Leading whitespace in indent-pre suppressing contexts
should not be escaped", "<blockquote>\n\n a\n <span>b</span>\n
c\n</blockquote>");
add("html2wt", "HTML tag with 'unnecessary' entity encoding in attributes",
"<span title=\"&\">foo</span>\n");
add("html2wt", "HTML tag with broken attribute value quoting", "<span
title=\"Hello world\">Foo</span>\n");
diff --git a/tests/parserTests.txt b/tests/parserTests.txt
index 8bdc74b..034282d 100644
--- a/tests/parserTests.txt
+++ b/tests/parserTests.txt
@@ -2057,13 +2057,28 @@
preformatted text.
This is preformatted text.
So is this.
-!! html
+!! html/php
<p> This is not
preformatted text.
</p>
<pre>This is preformatted text.
So is this.
</pre>
+!! html/parsoid
+<p> This is not
+ preformatted text.</p>
+<pre>This is preformatted text.
+ So is this.</pre>
+!! end
+
+!! test
+Space before tab needs nowiki pre protection
+!! options
+parsoid=html2wt
+!! html/parsoid
+<p> a</p>
+!! wikitext
+<nowiki> </nowiki> a
!! end
!! test
@@ -23209,14 +23224,12 @@
#### ------------------------------------------------------
!! test
1. Leading whitespace in SOL context should be escaped
-!! options
-parsoid
!! wikitext
<nowiki> </nowiki>a
<nowiki> </nowiki> a
-<nowiki> </nowiki>a(tab)
+ a(tab)
<nowiki> </nowiki> a
<!--cmt-->
@@ -23226,20 +23239,40 @@
<nowiki> </nowiki>b
a
-<nowiki> </nowiki>b
+ b
a
-<nowiki> </nowiki> b
-!! html
-<p> a</p>
-<p> a</p>
+ b
+!! html/php
+<p> a
+</p><p> a
+</p><p> a(tab)
+</p><p> a
+ a
+</p><p>a
+ b
+</p><p>a
+ b
+</p><p>a
+ b
+</p>
+!! html/parsoid
+<p><span typeof="mw:Nowiki"> </span>a</p>
+
+<p><span typeof="mw:Nowiki"> </span> a</p>
+
<p> a(tab)</p>
-<p> a</p>
-<p><!--cmt--> a</p>
+
+<p><span typeof="mw:Nowiki"> </span> a
+<!--cmt-->
+<span typeof="mw:Nowiki"> </span> a</p>
+
<p>a
- b</p>
+<span typeof="mw:Nowiki"> </span>b</p>
+
<p>a
b</p>
+
<p>a
b</p>
!! end
--
To view, visit https://gerrit.wikimedia.org/r/235277
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I1461a0e155477f57d9b1835b4e662c1ee85ba699
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Arlolra <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits