Sophivorus has uploaded a new change for review. https://gerrit.wikimedia.org/r/318095
Change subject: Don't match equal signs in param values ...................................................................... Don't match equal signs in param values Also rename method "scanForReferences" to "parse" Bug: T149138 Change-Id: Iba2daf2bbd637afa4acbfe7a76d484a4a5bcdeb8 --- M proveit.js 1 file changed, 14 insertions(+), 12 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/wikipedia/gadgets/ProveIt refs/changes/95/318095/1 diff --git a/proveit.js b/proveit.js index 28ff6de..5e51af8 100755 --- a/proveit.js +++ b/proveit.js @@ -115,7 +115,7 @@ page = data.pages[ page ]; proveit.templateData[ page.title ] = page; } - proveit.scanForReferences(); + proveit.parse(); }); }); @@ -209,7 +209,7 @@ } $( this ).addClass( 'active' ).siblings().removeClass( 'active' ); - proveit.scanForReferences(); + proveit.parse(); }); addTab.click( function () { @@ -232,11 +232,11 @@ }, /** - * Scan for references in the textbox and display them + * Parse the textbox for references and display them * * @return {void} */ - scanForReferences: function () { + parse: function () { // First define the list element var referenceList = $( '<ol>' ).attr( 'id', 'proveit-reference-list' ); @@ -342,25 +342,27 @@ // Extract the parameters and normalize them var paramsArray = match[2].split( '|' ), - paramString, paramNameAndValue, paramName, paramValue; + paramString, indexOfEqual, paramName, paramValue; paramsArray.shift(); // The first element is always empty for ( var i = 0; i < paramsArray.length; i++ ) { paramString = $.trim( paramsArray[ i ] ); + indexOfEqual = paramString.indexOf( '=' ); + // If there's no = sign, it means we matched a pipe inside a link or template in the previous run of the loop - // For example |param=[[Joe|Doe]] or |param={{Some|template}} - // So we append the current paramString to the PREVIOUS paramValue - if ( paramString.indexOf( '=' ) === -1 ) { + // for example |param=[[Joe|Doe]] or |param={{Some|template}} + // so we append the current paramString to the PREVIOUS paramValue + if ( indexOfEqual === -1 ) { reference.params[ paramName ] += '|' + paramString; continue; } - paramNameAndValue = paramString.split( '=' ); - paramName = $.trim( paramNameAndValue[0] ); - paramValue = $.trim( paramNameAndValue[1] ); + + paramName = $.trim( paramString.substring( 0, indexOfEqual ) ); + paramValue = $.trim( paramString.substring( indexOfEqual + 1 ) ); if ( !paramName || !paramValue ) { - continue; + continue; // Malformed param, maybe "|foo=" or "|=bar" } reference.params[ paramName ] = paramValue; -- To view, visit https://gerrit.wikimedia.org/r/318095 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iba2daf2bbd637afa4acbfe7a76d484a4a5bcdeb8 Gerrit-PatchSet: 1 Gerrit-Project: wikipedia/gadgets/ProveIt Gerrit-Branch: master Gerrit-Owner: Sophivorus <scheno...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits