Mvolz has uploaded a new change for review.

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

Change subject: Check templateField type
......................................................................

Check templateField type

Previously, didn't check templateField type for type
Array when citoidField was also an array and would
attempt to add arrays as a template parameter.
If there is a type mismatch, it ignores the field and
no longer tries to add it as a template parameter.

Bug: T100651
Change-Id: I0b897cace77ce47d952f4b53007404b13ea312d9
---
M modules/ve.ui.CiteFromIdInspector.js
1 file changed, 24 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Citoid 
refs/changes/40/214340/1

diff --git a/modules/ve.ui.CiteFromIdInspector.js 
b/modules/ve.ui.CiteFromIdInspector.js
index b961c80..fa7d977 100644
--- a/modules/ve.ui.CiteFromIdInspector.js
+++ b/modules/ve.ui.CiteFromIdInspector.js
@@ -599,22 +599,38 @@
        for ( citoidField in map ) {
                templateField = map[ citoidField ];
                // Construct parameters
-               if ( typeof templateField === 'string' && citation[ citoidField 
] !== undefined ) {
+               if ( typeof templateField === 'string' &&
+                       citation[ citoidField ] && typeof citation[ citoidField 
] === 'string') {
                        // Case: Citoid parameter directly equivalent to 
TemplateData parameter
-                       template.addParameter( new ve.dm.MWParameterModel( 
template, templateField, citation[citoidField ] ) );
-               } else if ( Array.isArray( citation[ citoidField ] ) ) {
+                       template.addParameter( new ve.dm.MWParameterModel(
+                               template, templateField, citation[ citoidField 
] )
+                       );
+               // Check that both typeof citoidField and templateField match
+               } else if ( Array.isArray( citation[ citoidField ] ) && 
Array.isArray( templateField ) ) {
                        // Case: Citoid parameter equivalent to 1 or 2D Array 
of TD parameters
                        for ( i = 0; i < citation[ citoidField ].length; i++ ) {
                                // Iterate through first dimension of array
-                               if ( typeof citation[ citoidField ][ i ] === 
'string' && templateField[ i ] !== undefined ) {
+                               if ( typeof citation[ citoidField ][ i ] === 
'string' &&
+                                       typeof templateField[ i ] === 'string') 
{
                                        // Case: Citoid parameter equivalent to 
1D Array of TD parameters
-                                       template.addParameter( new 
ve.dm.MWParameterModel( template, templateField[ i ], citation[ citoidField ][ 
i ] ) );
-                               } else if ( Array.isArray( citation[ 
citoidField ][ i ] ) ) {
+                                       template.addParameter(
+                                               new ve.dm.MWParameterModel(
+                                                       template, 
templateField[ i ], citation[ citoidField ][ i ]
+                                               )
+                                       );
+                               // Check that both typeof citoidField and 
templateField match
+                               } else if ( Array.isArray( citation[ 
citoidField ][ i ] ) &&
+                                       Array.isArray( templateField[ i ] )) {
                                        // Case: Citoid parameter equivalent to 
2D Array of TD parameters
                                        for ( j = 0; j < citation[ citoidField 
][ i ].length; j++ ) {
                                                // Iterate through 2nd 
dimension of Array
-                                               if ( typeof citation[ 
citoidField ][ i ][ j ] === 'string' && templateField[ i ] !== undefined && 
templateField[ i ][ j ] !== undefined ) {
-                                                       template.addParameter( 
new ve.dm.MWParameterModel( template, templateField[ i ][ j ], citation[ 
citoidField ][ i ][ j ] ) );
+                                               if ( typeof citation[ 
citoidField ][ i ][ j ] === 'string' &&
+                                                       templateField[ i ] && 
templateField[ i ][ j ] ) {
+                                                       template.addParameter(
+                                                               new 
ve.dm.MWParameterModel(
+                                                                       
template, templateField[ i ][ j ], citation[ citoidField ][ i ][ j ]
+                                                               )
+                                                       );
                                                }
                                        }
                                }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0b897cace77ce47d952f4b53007404b13ea312d9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Citoid
Gerrit-Branch: master
Gerrit-Owner: Mvolz <mv...@wikimedia.org>

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

Reply via email to