Marcoil has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/184645

Change subject: T73412: Preserve blank template parameters
......................................................................

T73412: Preserve blank template parameters

Blank template parameters ({{foo|=bar}} are valid, don't convert
them into positional ones.

Change-Id: I09faba60a2b2e496593eda814a4190ec2ed14b75
---
M lib/ext.core.TemplateHandler.js
M lib/mediawiki.WikitextSerializer.js
M tests/parserTests.txt
3 files changed, 18 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid 
refs/changes/45/184645/1

diff --git a/lib/ext.core.TemplateHandler.js b/lib/ext.core.TemplateHandler.js
index fc194b8..fa1d8ba 100644
--- a/lib/ext.core.TemplateHandler.js
+++ b/lib/ext.core.TemplateHandler.js
@@ -1000,7 +1000,10 @@
 
                // Number positional parameters
                var isPositional;
-               if (k === '') {
+               // Even if k is empty, we need to check v immediately follows. 
If not,
+               // it's a blank parameter name (which is valid) and we 
shouldn't make it
+               // positional.
+               if (k === '' && srcOffsets[1] === srcOffsets[2]) {
                        isPositional = true;
                        k = argIndex.toString();
                        argIndex++;
diff --git a/lib/mediawiki.WikitextSerializer.js 
b/lib/mediawiki.WikitextSerializer.js
index 41b8de5..72c7c10 100644
--- a/lib/mediawiki.WikitextSerializer.js
+++ b/lib/mediawiki.WikitextSerializer.js
@@ -446,6 +446,9 @@
 
                                                if (paramInfo.spc) {
                                                        spc = paramInfo.spc;
+                                               } else if 
(opts.serializeAsNamed && k === "") {
+                                                       // No spacing for blank 
parameters ({{foo|=bar}})
+                                                       spc = ['', '', '', ''];
                                                } //else {
                                                        // TODO: match the 
space style of other/ parameters!
                                                        //spc = ['', ' ', ' ', 
''];
diff --git a/tests/parserTests.txt b/tests/parserTests.txt
index acdf9fd..ffe77df 100644
--- a/tests/parserTests.txt
+++ b/tests/parserTests.txt
@@ -2519,6 +2519,17 @@
 <p about="#mwt1" typeof="mw:Transclusion" 
data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"a
 : b"}},"i":0}}]}'>a<span typeof="mw:Placeholder" 
data-parsoid='{"isDisplayHack":true}'> </span>: b</p>
 !! end
 
+## Bug T73412
+!! test
+Templates: Preserve blank parameter names
+!! options
+parsoid
+!! wikitext
+{{echo|=foo}}
+!! html
+<p about="#mwt1" typeof="mw:Transclusion" 
data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"":{"wt":"foo"}},"i":0}}]}'>foo</p>
+!! end
+
 ###
 ### Parsoid-centric tests for testing RT edge cases for pre
 ###

-- 
To view, visit https://gerrit.wikimedia.org/r/184645
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I09faba60a2b2e496593eda814a4190ec2ed14b75
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Marcoil <marc...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to