Subramanya Sastry has uploaded a new change for review.
https://gerrit.wikimedia.org/r/119081
Change subject: Improvement to detection of nested template ranges.
......................................................................
Improvement to detection of nested template ranges.
* Existing code for detecting nested templates stopped after
finding the first container rather than finding the outermost
container.
* The simple change in this patch fixes contrived examples that
come about from fostering.
------------
{|
{{echo|<div>}}
foo
{{echo|</div>}}
|}
------------
In this example, 3 template ranges are detected, all of which
are identical (fostered content + table). Nesting detection wasn't
picking up the outermost (in terms of wikitext source range)
template which resulted in a missing data-mw and resulting
screwup in RT-ing.
* Fixes a selser failure from a8374b63294ae31d494e5dd65cebc31a1392694b
Change-Id: I190e6c6081ecc79fea2bb4304a9cd41c14221158
---
M lib/dom.wrapTemplates.js
M tests/parserTests-blacklist.js
2 files changed, 8 insertions(+), 6 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid
refs/changes/81/119081/1
diff --git a/lib/dom.wrapTemplates.js b/lib/dom.wrapTemplates.js
index ac28c82..727e51f 100644
--- a/lib/dom.wrapTemplates.js
+++ b/lib/dom.wrapTemplates.js
@@ -277,7 +277,7 @@
}
// Record 'r'
- tpls[r.id] = true;
+ tpls[r.id] = r;
// Done
if (n === e) {
@@ -330,9 +330,12 @@
var other = s_keys[j];
if (other !== r.id &&
e_tpls[other]) {
foundIntersection =
true;
- // Record a range in
which 'r' is nested in.
- nestedRangesMap[r.id] =
other;
- break;
+ // Record the outermost
range in which 'r' is nested in.
+ if
(!nestedRangesMap[r.id]
+ ||
s_tpls[other].startOffset < s_tpls[nestedRangesMap[r.id]].startOffset)
+ {
+
nestedRangesMap[r.id] = other;
+ }
}
}
diff --git a/tests/parserTests-blacklist.js b/tests/parserTests-blacklist.js
index 0fcbe5a..77b30e0 100644
--- a/tests/parserTests-blacklist.js
+++ b/tests/parserTests-blacklist.js
@@ -164,7 +164,7 @@
add("wt2html", "Templates: HTML Tag: 2. Generation of HTML attr. value", "<div
style=\"'color:red;'\" about=\"#mwt2\" typeof=\"mw:ExpandedAttrs\"
data-mw='{\"attribs\":[[{\"txt\":\"style\"},{\"html\":\"<span
about=\\\"#mwt1\\\" typeof=\\\"mw:Transclusion\\\"
data-mw=\\\"{&quot;parts&quot;:[{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;echo&quot;,&quot;href&quot;:&quot;./Template:Echo&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;'color:red;'&quot;}},&quot;i&quot;:0}}]}\\\"
data-parsoid=\\\"{&quot;dsr&quot;:[11,32,null,null],&quot;pi&quot;:[[{&quot;k&quot;:&quot;1&quot;,&quot;spc&quot;:[&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;]}]]}\\\">'color:red;'</span>\"}]]}'
data-parsoid='{\"stx\":\"html\",\"a\":{\"style\":\"'color:red;'\"},\"sa\":{\"style\":\"{{echo|'color:red;'}}\"},\"dsr\":[0,42,33,6]}'>foo</div>");
add("wt2html", "Templates: HTML Tag: 3. Generation of HTML attr key and
value", "<div style=\"'color:red;'\" about=\"#mwt3\"
typeof=\"mw:ExpandedAttrs\"
data-mw='{\"attribs\":[[{\"txt\":\"style\",\"html\":\"<span
about=\\\"#mwt2\\\" typeof=\\\"mw:Transclusion\\\"
data-mw=\\\"{&quot;parts&quot;:[{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;echo&quot;,&quot;href&quot;:&quot;./Template:Echo&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;style&quot;}},&quot;i&quot;:0}}]}\\\"
data-parsoid=\\\"{&quot;dsr&quot;:[5,19,null,null],&quot;pi&quot;:[[{&quot;k&quot;:&quot;1&quot;,&quot;spc&quot;:[&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;]}]]}\\\">style</span>\"},{\"html\":\"<span
about=\\\"#mwt1\\\" typeof=\\\"mw:Transclusion\\\"
data-mw=\\\"{&quot;parts&quot;:[{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;echo&quot;,&quot;href&quot;:&quot;./Template:Echo&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;'color:red;'&quot;}},&quot;i&quot;:0}}]}\\\"
data-parsoid=\\\"{&quot;dsr&quot;:[20,41,null,null],&quot;pi&quot;:[[{&quot;k&quot;:&quot;1&quot;,&quot;spc&quot;:[&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;]}]]}\\\">'color:red;'</span>\"}]]}'
data-parsoid='{\"stx\":\"html\",\"a\":{\"style\":\"'color:red;'\"},\"sa\":{\"style\":\"{{echo|'color:red;'}}\"},\"dsr\":[0,51,42,6]}'>foo</div>");
add("wt2html", "Templates: Wiki Tables: 1a. Fostering of entire template
content", "<p about=\"#mwt2\" typeof=\"mw:Transclusion\"
data-mw='{\"parts\":[\"{|\\n\",{\"template\":{\"target\":{\"wt\":\"echo\",\"href\":\"./Template:Echo\"},\"params\":{\"1\":{\"wt\":\"a\"}},\"i\":0}},\"\\n|}\"]}'
data-parsoid='{\"fostered\":true,\"autoInsertedEnd\":true,\"dsr\":[0,16],\"pi\":[[{\"k\":\"1\",\"spc\":[\"\",\"\",\"\",\"\"]}]]}'>a</p><table
about=\"#mwt2\" data-parsoid='{\"dsr\":[0,16,2,2]}'>\n\n</table>");
-add("wt2html", "Templates: Wiki Tables: 1b. Fostering of entire template
content", "<div about=\"#mwt1\" typeof=\"mw:Transclusion\"
data-parsoid='{\"stx\":\"html\",\"fostered\":true,\"autoInsertedEnd\":true,\"dsr\":[0,0]}'
data-mw=\"{}\">\n<p data-parsoid='{\"dsr\":[18,21,0,0]}'>foo</p>\n</div><table
about=\"#mwt1\" typeof=\"mw:Transclusion\"
data-mw='{\"parts\":[\"{|\\n\",{\"template\":{\"target\":{\"wt\":\"echo\",\"href\":\"./Template:Echo\"},\"params\":{\"1\":{\"wt\":\"<div>\"}},\"i\":0}},\"\\nfoo\\n\",{\"template\":{\"target\":{\"wt\":\"echo\",\"href\":\"./Template:Echo\"},\"params\":{\"1\":{\"wt\":\"</div>\"}},\"i\":1}},\"\\n|}\"]}'
data-parsoid='{\"dsr\":[0,40,2,2],\"src\":\"{|\\n{{echo|<div>}}\\nfoo\\n{{echo|</div>}}\\n|}\",\"pi\":[[{\"k\":\"1\",\"spc\":[\"\",\"\",\"\",\"\"]}],[{\"k\":\"1\",\"spc\":[\"\",\"\",\"\",\"\"]}]]}'>\n\n</table>");
+add("wt2html", "Templates: Wiki Tables: 1b. Fostering of entire template
content", "<div about=\"#mwt3\" typeof=\"mw:Transclusion\"
data-mw='{\"parts\":[\"{|\\n\",{\"template\":{\"target\":{\"wt\":\"echo\",\"href\":\"./Template:Echo\"},\"params\":{\"1\":{\"wt\":\"<div>\"}},\"i\":0}},\"\\nfoo\\n\",{\"template\":{\"target\":{\"wt\":\"echo\",\"href\":\"./Template:Echo\"},\"params\":{\"1\":{\"wt\":\"</div>\"}},\"i\":1}},\"\\n|}\"]}'
data-parsoid='{\"stx\":\"html\",\"fostered\":true,\"autoInsertedEnd\":true,\"dsr\":[0,40],\"pi\":[[{\"k\":\"1\",\"spc\":[\"\",\"\",\"\",\"\"]}],[{\"k\":\"1\",\"spc\":[\"\",\"\",\"\",\"\"]}]]}'>\n<p
data-parsoid='{\"dsr\":[18,21,0,0]}'>foo</p>\n</div><table about=\"#mwt3\"
data-parsoid='{\"dsr\":[0,40,2,2]}'>\n\n</table>");
add("wt2html", "Templates: Wiki Tables: 2. Fostering of partial template
content", "<p about=\"#mwt2\" typeof=\"mw:Transclusion\"
data-mw='{\"parts\":[\"{|\\n\",{\"template\":{\"target\":{\"wt\":\"echo\",\"href\":\"./Template:Echo\"},\"params\":{\"1\":{\"wt\":\"a\\n<div>b</div>\"}},\"i\":0}},\"\\n|}\"]}'
data-parsoid='{\"fostered\":true,\"autoInsertedEnd\":true,\"dsr\":[0,29],\"pi\":[[{\"k\":\"1\",\"spc\":[\"\",\"\",\"\",\"\"]}]]}'>a</p><div
about=\"#mwt2\"
data-parsoid='{\"stx\":\"html\",\"fostered\":true,\"autoInsertedEnd\":true,\"dsr\":[0,0]}'>b</div><table
about=\"#mwt2\" data-parsoid='{\"dsr\":[0,29,2,2]}'>\n\n\n</table>");
add("wt2html", "Templates: Wiki Tables: 3. td-content via multiple templates",
"<table data-parsoid='{\"dsr\":[0,34,2,2]}'>\n<tbody about=\"#mwt1\"
typeof=\"mw:Transclusion\"
data-mw='{\"parts\":[{\"template\":{\"target\":{\"wt\":\"echo\",\"href\":\"./Template:Echo\"},\"params\":{\"1\":{\"wt\":\"{{pipe}}a\"}},\"i\":0}},{\"template\":{\"target\":{\"wt\":\"echo\",\"href\":\"./Template:Echo\"},\"params\":{\"1\":{\"wt\":\"b\"}},\"i\":1}},\"\\n\"]}'
data-parsoid='{\"dsr\":[3,32,0,0],\"pi\":[[{\"k\":\"1\",\"spc\":[\"\",\"\",\"\",\"\"]}],[{\"k\":\"1\",\"spc\":[\"\",\"\",\"\",\"\"]}]]}'><tr
data-parsoid='{\"autoInsertedEnd\":true,\"autoInsertedStart\":true,\"dsr\":[null,31,0,0]}'><td
data-parsoid='{\"autoInsertedEnd\":true,\"dsr\":[null,31,null,0]}'>a<span
data-parsoid='{\"dsr\":[21,31,null,null],\"src\":\"{{echo|b}}\"}'>b</span></td></tr>\n</tbody></table>");
add("wt2html", "Templates: Wiki Tables: 4. Templated tags, no content",
"<table about=\"#mwt2\" typeof=\"mw:Transclusion\"
data-mw='{\"parts\":[{\"template\":{\"target\":{\"wt\":\"tbl-start\",\"href\":\"./Template:Tbl-start\"},\"params\":{},\"i\":0}},\"\\n\",{\"template\":{\"target\":{\"wt\":\"tbl-end\",\"href\":\"./Template:Tbl-end\"},\"params\":{},\"i\":1}}]}'
data-parsoid='{\"dsr\":[0,25,null,null],\"pi\":[[],[]]}'>\n</table>");
@@ -2927,7 +2927,6 @@
add("selser", "Templates: HTML Tables: 5. Proper fostering of categories from
inside [0,[2],0,2,2,0,0,[1]]",
"<table><!--c0u2c9uer91cerk9-->[[Category:foo1]]<tr><td>foo</td></tr></table>\n8hyzimw3d00vbo6r<!--Two
categories (Bug
50330)-->12c9zldofglj714i\n<table><tr><td>foo</td></tr></table>");
add("selser", "Templates: HTML Tables: 5. Proper fostering of categories from
inside [0,[[3]],2,0,0,4,0,[[[4]]]]", "<table></table>frdce0reto2h85mi\n<!--Two
categories (Bug
50330)-->\n3lz5b6rsfydjkyb9<table><tr><td>6xqvzsggdh392j4i</td></tr></table>");
add("selser", "Templates: HTML Tables: 5. Proper fostering of categories from
inside [0,4,4,0,0,3,2,[3]]", "4izrbq79n79442t9nmwv8fylt48fflxr<!--Two
categories (Bug 50330)-->\nzjdiwp9jubejc3di<table></table>");
-add("selser", "Templates: Wiki Tables: 1b. Fostering of entire template
content 5", "");
add("selser", "Templates: Wiki Tables: 3. td-content via multiple templates
[[4,0]]", "{|<!--hfujv0dg8gmbo6r-->\n{{echo|{{pipe}}a}}{{echo|b}}\n|}");
add("selser", "pre-save transform: mixed tag case [2]",
"rlq31ytw4um78pvi\n\n<NOwiki>'''not wiki'''</noWIKI>");
add("selser", "pre-save transform: mixed tag case [1]", "<NOwiki>'''not
wiki'''</noWIKI>");
--
To view, visit https://gerrit.wikimedia.org/r/119081
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I190e6c6081ecc79fea2bb4304a9cd41c14221158
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Subramanya Sastry <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits