jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/350005 )
Change subject: Fix crasher from a9cfa9c9
......................................................................
Fix crasher from a9cfa9c9
* On /hi.wikipedia.org/v3/page/html/फर्डिनैंड_कोह्न/2674115
* Ignoring subst came from aaca5eac but doesn't seem right. However,
we should be ignoring safesubt, since that's designed to work when
transcluded.
Change-Id: Ia15c4e1aa36d13ea0d25870e47f6248ca297066d
---
M lib/wt2html/tt/TemplateHandler.js
M tests/parserTests-blacklist.js
2 files changed, 12 insertions(+), 5 deletions(-)
Approvals:
Subramanya Sastry: Looks good to me, approved
jenkins-bot: Verified
diff --git a/lib/wt2html/tt/TemplateHandler.js
b/lib/wt2html/tt/TemplateHandler.js
index 436ca09..c70f701 100644
--- a/lib/wt2html/tt/TemplateHandler.js
+++ b/lib/wt2html/tt/TemplateHandler.js
@@ -441,9 +441,16 @@
target = Util.tokensToString(targetToks);
}
- // Without a trim(), we get bug T147742 because
- // the prefix === target check further below fails!
- target = target.trim().replace(/^(safe)?subst:/, '');
+ var normalizeTarget = function(txt) {
+ // Without a trim(), we get bug T147742 because the prefix ===
target
+ // check further below fails!
+ txt = txt.trim();
+ // safesubst found in content should be treated as if no
modifier were
+ // present. See
https://en.wikipedia.org/wiki/Help:Substitution#The_safesubst:_modifier
+ return txt.replace(/^safesubst:/, '');
+ };
+ target = normalizeTarget(target);
+
var pieces = target.split(':');
var prefix = pieces[0].trim();
// The check for pieces.length > 1 is require to distinguish between
@@ -471,7 +478,7 @@
if (typeof firstTok === 'string') {
targetToks = targetToks.slice(1);
// Strip parser-func / magic-word prefix
- firstTok = firstTok.replace(new RegExp("^" + prefix,
'i'), '');
+ firstTok = normalizeTarget(firstTok).replace(new
RegExp("^" + prefix, 'i'), '');
// Strip ":" after skipping empty tokens, if any
if (isPF) {
diff --git a/tests/parserTests-blacklist.js b/tests/parserTests-blacklist.js
index 52941b5..883dcab 100644
--- a/tests/parserTests-blacklist.js
+++ b/tests/parserTests-blacklist.js
@@ -128,7 +128,7 @@
add("wt2html", "Templates: Ugly nesting: 1. Quotes opened/closed across
templates (echo)", "<p data-parsoid='{\"dsr\":[0,40,0,0]}'><i about=\"#mwt1\"
typeof=\"mw:Transclusion\"
data-parsoid='{\"dsr\":[0,40,null,null],\"pi\":[[{\"k\":\"1\"}],[{\"k\":\"1\"}],[{\"k\":\"1\"}]]}'
data-mw='{\"parts\":[{\"template\":{\"target\":{\"wt\":\"echo\",\"href\":\"./Template:Echo\"},\"params\":{\"1\":{\"wt\":\"''a\"}},\"i\":0}},{\"template\":{\"target\":{\"wt\":\"echo\",\"href\":\"./Template:Echo\"},\"params\":{\"1\":{\"wt\":\"b''c''d\"}},\"i\":1}},{\"template\":{\"target\":{\"wt\":\"echo\",\"href\":\"./Template:Echo\"},\"params\":{\"1\":{\"wt\":\"''e\"}},\"i\":2}}]}'>ab</i><span
about=\"#mwt1\">c</span><i about=\"#mwt1\">d</i><span
about=\"#mwt1\">e</span></p>");
add("wt2html", "Templates: Ugly templates: 1. Navbox template parses badly
leading to table misnesting\n(Parsoid-centric)", "<table about=\"#mwt1\"
typeof=\"mw:Transclusion\"
data-parsoid='{\"stx\":\"html\",\"dsr\":[0,32,2,null],\"firstWikitextNode\":\"TABLE_html\",\"pi\":[[{\"k\":\"1\"}]]}'
data-mw='{\"parts\":[\"{|\\n|\",{\"template\":{\"target\":{\"wt\":\"echo\",\"href\":\"./Template:Echo\"},\"params\":{\"1\":{\"wt\":\"foo</table>\"}},\"i\":0}},\"\\n|bar\\n|}\"]}'>\n<tbody><tr><td>foo</td></tr></tbody></table><span
about=\"#mwt1\">\n|bar\n</span>");
add("wt2html", "Templates: Ugly templates: 4. newline-only template parameter
inconsistency", "<span about=\"#mwt1\" typeof=\"mw:Transclusion\"
data-parsoid='{\"pi\":[[{\"k\":\"1\"}]],\"dsr\":[0,10,null,null]}'
data-mw='{\"parts\":[{\"template\":{\"target\":{\"wt\":\"echo\",\"href\":\"./Template:Echo\"},\"params\":{\"1\":{\"wt\":\"\\n\"}},\"i\":0}}]}'>\n</span>");
-add("wt2html", "subst: does not work during normal parse", "<p about=\"#mwt1\"
typeof=\"mw:Transclusion\" data-parsoid='{\"dsr\":[0,13,0,0],\"pi\":[[]]}'
data-mw='{\"parts\":[{\"template\":{\"target\":{\"wt\":\"SubstTest\",\"href\":\"./Template:SubstTest\"},\"params\":{},\"i\":0}}]}'>Foobar</p>");
+add("wt2html", "subst: does not work during normal parse", "<p about=\"#mwt1\"
typeof=\"mw:Transclusion\" data-parsoid='{\"dsr\":[0,13,0,0],\"pi\":[[]]}'
data-mw='{\"parts\":[{\"template\":{\"target\":{\"wt\":\"SubstTest\",\"href\":\"./Template:SubstTest\"},\"params\":{},\"i\":0}}]}'>{{<includeonly>subst:</includeonly>Includes}}</p>");
add("wt2html", "message transform: magic variables", "<p about=\"#mwt1\"
typeof=\"mw:Transclusion\" data-parsoid='{\"dsr\":[0,12,0,0],\"pi\":[[]]}'
data-mw='{\"parts\":[{\"template\":{\"target\":{\"wt\":\"SITENAME\",\"function\":\"sitename\"},\"params\":{},\"i\":0}}]}'>MediaWiki</p>");
add("wt2html", "message transform: should not transform wiki markup", "<p
data-parsoid='{\"dsr\":[0,8,0,0]}'><i
data-parsoid='{\"dsr\":[0,8,2,2]}'>test</i></p>");
add("wt2html", "message transform: <noinclude> in transcluded template
(T6926)", "<p about=\"#mwt1\" typeof=\"mw:Transclusion\"
data-parsoid='{\"dsr\":[0,12,0,0],\"pi\":[[]]}'
data-mw='{\"parts\":[{\"template\":{\"target\":{\"wt\":\"Includes\",\"href\":\"./Template:Includes\"},\"params\":{},\"i\":0}}]}'>Foobar</p>");
--
To view, visit https://gerrit.wikimedia.org/r/350005
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ia15c4e1aa36d13ea0d25870e47f6248ca297066d
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Arlolra <[email protected]>
Gerrit-Reviewer: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits