/**
* Massage parameters from the nice format we accept into a format suitable for the API.
*
+ * NOTE: A value of undefined/null in an array will be represented by Array#join()
+ * as the empty string. Should we filter silently? Warn? Leave as-is?
+ *
* @private
* @param {Object} parameters (modified in-place)
* @param {boolean} useUS Whether to use U+001F when joining multi-valued parameters.
return api.post( { action: 'test' }, { contentType: 'multipart/form-data' } );
} );
- QUnit.test( 'Converting arrays to pipe-separated', function ( assert ) {
+ QUnit.test( 'Converting arrays to pipe-separated (string)', function ( assert ) {
var api = new mw.Api();
this.server.respond( function ( request ) {
return api.get( { test: [ 'foo', 'bar', 'baz' ] } );
} );
+ QUnit.test( 'Converting arrays to pipe-separated (mw.Title)', function ( assert ) {
+ var api = new mw.Api();
+
+ this.server.respond( function ( request ) {
+ assert.ok( request.url.match( /test=Foo%7CBar/ ), 'Pipe-separated value was submitted' );
+ request.respond( 200, { 'Content-Type': 'application/json' }, '[]' );
+ } );
+
+ return api.get( { test: [ new mw.Title( 'Foo' ), new mw.Title( 'Bar' ) ] } );
+ } );
+
+ QUnit.test( 'Converting arrays to pipe-separated (misc primitives)', function ( assert ) {
+ var api = new mw.Api();
+
+ this.server.respond( function ( request ) {
+ assert.ok( request.url.match( /test=true%7Cfalse%7C%7C%7C0%7C1%2E2/ ), 'Pipe-separated value was submitted: ' + request.url );
+ request.respond( 200, { 'Content-Type': 'application/json' }, '[]' );
+ } );
+
+ // undefined/null will become empty string
+ return api.get( { test: [ true, false, undefined, null, 0, 1.2 ] } );
+ } );
+
QUnit.test( 'Omitting false booleans', function ( assert ) {
var api = new mw.Api();