diff --git a/lib/src/utils.dart b/lib/src/utils.dart index 789c2d964f..18079dbd4e 100644 --- a/lib/src/utils.dart +++ b/lib/src/utils.dart @@ -13,6 +13,9 @@ import 'byte_stream.dart'; /// mapToQuery({"foo": "bar", "baz": "bang"}); /// //=> "foo=bar&baz=bang" String mapToQuery(Map map, {Encoding encoding}) { + var nullKeys = map.keys.where((k) => (map[k] == null)).toList(); + nullKeys.forEach(map.remove); // -- remove elements with null values + var pairs = >[]; map.forEach((key, value) => pairs.add([Uri.encodeQueryComponent(key, encoding: encoding), diff --git a/test/io/http_test.dart b/test/io/http_test.dart index 2419e198ef..041f7de82f 100644 --- a/test/io/http_test.dart +++ b/test/io/http_test.dart @@ -125,7 +125,8 @@ main() { 'User-Agent': 'Dart' }, body: { 'some-field': 'value', - 'other-field': 'other value' + 'other-field': 'other value', + 'null-field': null }).then((response) { expect(response.statusCode, equals(200)); expect(response.body, parse(equals({ @@ -229,7 +230,8 @@ main() { 'User-Agent': 'Dart' }, body: { 'some-field': 'value', - 'other-field': 'other value' + 'other-field': 'other value', + 'null-field': null }).then((response) { expect(response.statusCode, equals(200)); expect(response.body, parse(equals({ @@ -333,7 +335,8 @@ main() { 'User-Agent': 'Dart' }, body: { 'some-field': 'value', - 'other-field': 'other value' + 'other-field': 'other value', + 'null-field': null }).then((response) { expect(response.statusCode, equals(200)); expect(response.body, parse(equals({