Skip to content

Commit

Permalink
fix json encoding with execute
Browse files Browse the repository at this point in the history
  • Loading branch information
hpoul committed Aug 22, 2021
1 parent dc135e5 commit e2d6a83
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2.4.1+2

- Fix error when sending json data with `execute()` [#11](https://github.com/isoos/postgresql-dart/pull/11)

## 2.4.1+1

- Fix error when passing `allowReuse: null` into `query()` [#8](https://github.com/isoos/postgresql-dart/pull/8)
Expand Down
6 changes: 3 additions & 3 deletions lib/src/text_codec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class PostgresTextEncoder {
}

if (value is Map) {
return _encodeJSON(value);
return _encodeJSON(value, escapeStrings);
}

if (value is PgPoint) {
Expand Down Expand Up @@ -152,7 +152,7 @@ class PostgresTextEncoder {
return "'$string'";
}

String _encodeJSON(dynamic value) {
String _encodeJSON(dynamic value, bool escapeStrings) {
if (value == null) {
return 'null';
}
Expand All @@ -161,7 +161,7 @@ class PostgresTextEncoder {
return "'${json.encode(value)}'";
}

return json.encode(value);
return _encodeString(json.encode(value), escapeStrings);
}

String _encodePoint(PgPoint value) {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: postgres
description: PostgreSQL database driver. Supports statement reuse and binary protocol.
version: 2.4.1+1
version: 2.4.1+2
homepage: https://github.com/isoos/postgresql-dart

environment:
Expand Down
9 changes: 6 additions & 3 deletions test/encoding_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -546,9 +546,12 @@ void main() {
});

test('Encode JSONB', () {
expect(encoder.convert({'a': 'b'}), '{"a":"b"}');
expect(encoder.convert({'a': true}), '{"a":true}');
expect(encoder.convert({'b': false}), '{"b":false}');
expect(encoder.convert({'a': 'b'}, escapeStrings: false), '{"a":"b"}');
expect(encoder.convert({'a': true}, escapeStrings: false), '{"a":true}');
expect(
encoder.convert({'b': false}, escapeStrings: false), '{"b":false}');
expect(encoder.convert({'a': true}), '\'{"a":true}\'');
expect(encoder.convert({'b': false}), '\'{"b":false}\'');
});

test('Attempt to infer unknown type throws exception', () {
Expand Down

0 comments on commit e2d6a83

Please sign in to comment.