jenkins-bot has submitted this change and it was merged. Change subject: Deal with entities/nowikis in templated attrs ......................................................................
Deal with entities/nowikis in templated attrs * Fix #1: Fix code in attribute expander that deals with reparse-kv scenarios to convert the entire token stream to string (rather than stop at first non-string token). Prior to this fix, all those non-string tokens were being ignored which doesn't make sense (that info was lost and not being used anywhere). In any case, if we are going to reparse a string to k=v attributes, we should convert the token array to a string by using all avalable info (from nowiki and entity spans for ex.) * Fix #2: In the td-fixup code, collection of attribute content should similarly collect text from both nowiki and entity spans, not just nowiki spans. * Fixes the snippets in the bug report and more. * Added two parser tests for each of the two fixes above. Bug: T69850 Bug: T90028 Change-Id: I0179043fb612a791b4835c5dff9ff9962e258a5c --- M lib/dom.t.TableFixups.js M lib/ext.core.AttributeExpander.js M lib/mediawiki.Util.js M tests/parserTests.txt 4 files changed, 48 insertions(+), 5 deletions(-) Approvals: Marcoil: Looks good to me, approved jenkins-bot: Verified diff --git a/lib/dom.t.TableFixups.js b/lib/dom.t.TableFixups.js index 353caa0..778d623 100644 --- a/lib/dom.t.TableFixups.js +++ b/lib/dom.t.TableFixups.js @@ -134,7 +134,7 @@ // So, if we hit anything else, there is nothing more // to do here! return buildRes(); - } else if (transclusionNode && DU.hasTypeOf(child, 'mw:Nowiki')) { + } else if (transclusionNode && /^mw:(Nowiki|Entity)$/.test(child.getAttribute("typeof"))) { // Nowiki span added in the template to protect otherwise // meaningful wikitext chars used in attributes. buf.push(child.textContent); diff --git a/lib/ext.core.AttributeExpander.js b/lib/ext.core.AttributeExpander.js index 25f1953..cf89a72 100644 --- a/lib/ext.core.AttributeExpander.js +++ b/lib/ext.core.AttributeExpander.js @@ -311,11 +311,10 @@ expandedA.k = expandedK; - // Check if we need to deal with the Reparse-KV-string scenario - // from the documentation comment above. + // Check if we need to deal with the Reparse-KV-string scenario. + // (See documentation comment above) if (expandedA.v === '') { - var kArray = Util.tokensToString(expandedK, true), - kStr = (kArray.constructor === String) ? kArray : kArray[0], + var kStr = Util.tokensToString(expandedK), kvs = /=/.test(kStr) ? this.tokenizer.tokenize(kStr, 'generic_attributes') : null; if (kvs) { diff --git a/lib/mediawiki.Util.js b/lib/mediawiki.Util.js index b46a158..41141cb 100644 --- a/lib/mediawiki.Util.js +++ b/lib/mediawiki.Util.js @@ -634,6 +634,8 @@ } else if ( strict ) { // If strict, return accumulated string on encountering first non-text token return [out, tokens.slice( i )]; + } else if (Array.isArray(token)) { + out += this.tokensToString(token, false, stripEmptyLineMeta); } } return out; diff --git a/tests/parserTests.txt b/tests/parserTests.txt index 486a64b..29f9749 100644 --- a/tests/parserTests.txt +++ b/tests/parserTests.txt @@ -69,6 +69,12 @@ | !! endarticle +!! article +Template:= +!! text +<nowiki>=</nowiki> +!! endarticle + !!article MediaWiki:bad image list !!text @@ -124,6 +130,13 @@ <noinclude> |</noinclude>style="color:red;"|Foo |Bar||Baz +!! endarticle + +!! article +Template:table_attribs_3 +!! text +<noinclude> +|</noinclude>style{{=}}"background:#f9f9f9;"|Foo !! endarticle !! article @@ -10506,6 +10519,35 @@ </tbody></table> !!end +!! test +1. Entities and nowikis inside templated attributes should be handled correctly +!! wikitext +<div {{echo|style{{=}}"background:#f9f9f9;"}}>foo</div> +!! html/php +<div style="background:#f9f9f9;">foo</div> + +!! html/parsoid +<div style="background:#f9f9f9;" about="#mwt3" typeof="mw:ExpandedAttrs" data-parsoid='{"stx":"html"}' data-mw='{"attribs":[[{"txt":"style","html":"<span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid=\"{&quot;pi&quot;:[[{&quot;k&quot;:&quot;1&quot;,&quot;spc&quot;:[&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;]}]],&quot;dsr&quot;:[5,49,null,null]}\" 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;background:&amp;#35;f9f9f9;\\&quot;&quot;}},&quot;i&quot;:0}}]}\">style</span><span typeof=\"mw:Nowiki\" about=\"#mwt1\" data-parsoid=\"{}\">=</span><span about=\"#mwt1\" data-parsoid=\"{}\">\"background:</span><span typeof=\"mw:Entity\" about=\"#mwt1\" data-parsoid=\"{&quot;src&quot;:&quot;&amp;#35;&quot;,&quot;srcContent&quot;:&quot;#&quot;}\">#</span><span about=\"#mwt1\" data-parsoid=\"{}\">f9f9f9;\"</span>"},{"html":""}]]}'>foo</div> +!! end + +!! test +2. Entities and nowikis inside templated attributes should be handled correctly +!! wikitext +{| +|{{table_attribs_3}} +|} +!! html/php +<table> +<tr> +<td style="background:#f9f9f9;">Foo +</td></tr></table> + +!! html/parsoid +<table> +<tbody><tr data-parsoid='{"autoInsertedEnd":true,"autoInsertedStart":true}'><td style="background:#f9f9f9;" typeof="mw:Transclusion" about="#mwt1" data-parsoid='{"autoInsertedEnd":true,"pi":[[]]}' data-mw='{"parts":["|",{"template":{"target":{"wt":"table_attribs_3","href":"./Template:Table_attribs_3"},"params":{},"i":0}}]}'>Foo</td></tr> +</tbody></table> +!! end + !!test Templates: HTML Tables: 1. Generating start of a HTML table !! wikitext -- To view, visit https://gerrit.wikimedia.org/r/195491 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I0179043fb612a791b4835c5dff9ff9962e258a5c Gerrit-PatchSet: 4 Gerrit-Project: mediawiki/services/parsoid Gerrit-Branch: master Gerrit-Owner: Subramanya Sastry <ssas...@wikimedia.org> Gerrit-Reviewer: Arlolra <abrea...@wikimedia.org> Gerrit-Reviewer: Cscott <canan...@wikimedia.org> Gerrit-Reviewer: Marcoil <marc...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits