Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/364192 )

Change subject: Fix multivalue serialization
......................................................................

Fix multivalue serialization

Empty array was converted to `undefined`, which is not correct.
Should be empty string

Change-Id: If37a3dffad649397d12268f2dbbc23dd3c1364bd
---
M src/RepoApi.js
M tests/RepoApi.tests.js
2 files changed, 14 insertions(+), 1 deletion(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseJavaScriptApi 
refs/changes/92/364192/1

diff --git a/src/RepoApi.js b/src/RepoApi.js
index 14c0365..fddadf4 100644
--- a/src/RepoApi.js
+++ b/src/RepoApi.js
@@ -849,7 +849,9 @@
         */
        normalizeMultiValue: function ( value ) {
                if ( Array.isArray( value ) ) {
-                       value = value.join( '\x1f' );
+                       return value.map( function (item) {
+                               return '\x1f' + item;
+                       } ).join('');
                }
 
                // We must enforce the alternative separation character, see 
ApiBase.php::explodeMultiValue.
diff --git a/tests/RepoApi.tests.js b/tests/RepoApi.tests.js
index c75213b..ed0cb96 100644
--- a/tests/RepoApi.tests.js
+++ b/tests/RepoApi.tests.js
@@ -662,4 +662,15 @@
        assert.strictEqual( getParam( mock.spy, 'summary', 2 ), undefined );
 } );
 
+QUnit.test( 'normalizeMultiValue()', function ( assert ) {
+       var mock = mockApi();
+
+       assert.equal( mock.api.normalizeMultiValue( [] ), '', 'empty array -> 
empty string' );
+       assert.equal(
+               mock.api.normalizeMultiValue( ['val1', 'val2'] ),
+               '\x1fval1\x1fval2',
+               'array values are prefixed with `\\x1f`'
+       );
+} );
+
 }( mediaWiki, wikibase, QUnit, sinon ) );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If37a3dffad649397d12268f2dbbc23dd3c1364bd
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikibaseJavaScriptApi
Gerrit-Branch: master
Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) <[email protected]>

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

Reply via email to