jenkins-bot has submitted this change and it was merged.

Change subject: Fix escapeParams in transclusions to not escape other 
transclusions
......................................................................


Fix escapeParams in transclusions to not escape other transclusions

Use a stack counter to work out if we are inside a another template
call.

Bug: 49854
Change-Id: Ic0b97520b1696c3cf292111c7052502d5ccad648
---
M modules/ve/dm/nodes/ve.dm.MWTransclusionNode.js
M modules/ve/test/dm/nodes/ve.dm.MWTransclusionNode.test.js
2 files changed, 53 insertions(+), 5 deletions(-)

Approvals:
  Catrope: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/ve/dm/nodes/ve.dm.MWTransclusionNode.js 
b/modules/ve/dm/nodes/ve.dm.MWTransclusionNode.js
index 94afb0d..4c3df34 100644
--- a/modules/ve/dm/nodes/ve.dm.MWTransclusionNode.js
+++ b/modules/ve/dm/nodes/ve.dm.MWTransclusionNode.js
@@ -111,9 +111,10 @@
  * @returns {string} Escaped parameter value
  */
 ve.dm.MWTransclusionNode.static.escapeParameter = function ( param ) {
-       var match, input = param, output = '', inNowiki = false;
+       var match, needsNowiki, input = param, output = '',
+               inNowiki = false, bracketStack = 0;
        while ( input.length > 0 ) {
-               match = input.match( /(?:\}\})+|\|+|<\/?nowiki>|<nowiki\s*\/>/ 
);
+               match = input.match( 
/(?:\{\{)+|(?:\}\})+|\|+|<\/?nowiki>|<nowiki\s*\/>/ );
                if ( !match ) {
                        output += input;
                        break;
@@ -128,13 +129,30 @@
                                output += match[0];
                        }
                } else {
+                       needsNowiki = true;
                        if ( match[0] === '<nowiki>' ) {
                                inNowiki = true;
-                               output += match[0];
+                               needsNowiki = false;
                        } else if ( match[0] === '</nowiki>' || match[0].match( 
/<nowiki\s*\/>/ ) ) {
-                               output += match[0];
-                       } else {
+                               needsNowiki = false;
+                       } else if ( match[0].match( /(?:\{\{)+/ ) ) {
+                               bracketStack++;
+                               needsNowiki = false;
+                       } else if ( match[0].match( /(?:\}\})+/ ) ) {
+                               if ( bracketStack > 0 ) {
+                                       bracketStack--;
+                                       needsNowiki = false;
+                               }
+                       } else if ( match[0].match( /\|+/ ) ) {
+                               if ( bracketStack > 0 ) {
+                                       needsNowiki = false;
+                               }
+                       }
+
+                       if ( needsNowiki ) {
                                output += '<nowiki>' + match[0] + '</nowiki>';
+                       } else {
+                               output += match[0];
                        }
                }
        }
diff --git a/modules/ve/test/dm/nodes/ve.dm.MWTransclusionNode.test.js 
b/modules/ve/test/dm/nodes/ve.dm.MWTransclusionNode.test.js
index c26fa52..3b4cac9 100644
--- a/modules/ve/test/dm/nodes/ve.dm.MWTransclusionNode.test.js
+++ b/modules/ve/test/dm/nodes/ve.dm.MWTransclusionNode.test.js
@@ -61,6 +61,36 @@
                                }
                        },
                        'wikitext': '{{foo|bar=You should try using 
<nowiki>{{ping|foo=bar|2=1}}</nowiki> as a transclusion!}}'
+               },
+               {
+                       'msg': 'parameter containing another template 
invocation',
+                       'mw': {
+                               'target': { 'wt': 'foo' },
+                               'params': {
+                                       'bar': { 'wt': '{{ping|foo=bar|2=1}}' }
+                               }
+                       },
+                       'wikitext': '{{foo|bar={{ping|foo=bar|2=1}}}}'
+               },
+               {
+                       'msg': 'parameter containing another parameter',
+                       'mw': {
+                               'target': { 'wt': 'foo' },
+                               'params': {
+                                       'bar': { 'wt': '{{{1}}}' }
+                               }
+                       },
+                       'wikitext': '{{foo|bar={{{1}}}}}'
+               },
+               {
+                       'msg': 'parameter containing unmatched close brackets 
and floating pipes',
+                       'mw': {
+                               'target': { 'wt': 'foo' },
+                               'params': {
+                                       'bar': { 'wt': '}} |' }
+                               }
+                       },
+                       'wikitext': '{{foo|bar=<nowiki>}}</nowiki> 
<nowiki>|</nowiki>}}'
                }
        ];
        QUnit.expect( cases.length );

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ic0b97520b1696c3cf292111c7052502d5ccad648
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to