Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,12 @@ class RestTransport implements DataConnectTransport {
headers: headers,
);
Map<String, dynamic> bodyJson =
jsonDecode(r.body) as Map<String, dynamic>;
jsonDecode(utf8.decode(r.bodyBytes)) as Map<String, dynamic>;

if (r.statusCode != 200) {
String message =
bodyJson.containsKey('message') ? bodyJson['message']! : r.body;
String message = bodyJson.containsKey('message')
? bodyJson['message']!
: utf8.decode(r.bodyBytes);
throw DataConnectError(
r.statusCode == 401
? DataConnectErrorCode.unauthorized
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,44 @@ void main() {
).called(1);
});

test(
'regression #17290 - invokeOperation should correctly decode UTF-8 response with international characters',
() async {
// Simulate a server response with Korean characters, where the
// Content-Type header does NOT include charset=utf-8 (which is
// what the Firebase emulator sends). Without explicit UTF-8
// decoding, the http package defaults to latin1, corrupting
// multi-byte characters.
const koreanJson =
'{"data": {"name": "\ud55c\uad6d\uc5b4 \ud14c\uc2a4\ud2b8"}}';
final mockResponse = http.Response.bytes(
utf8.encode(koreanJson),
200,
headers: {'content-type': 'application/json'},
);
when(
mockHttpClient.post(
any,
headers: anyNamed('headers'),
body: anyNamed('body'),
),
).thenAnswer((_) async => mockResponse);

final deserializer = (String data) => 'Deserialized Data';

final result = await transport.invokeOperation(
'testQuery',
'executeQuery',
deserializer,
null,
null,
null,
);

expect(result.data['data']['name'],
equals('\ud55c\uad6d\uc5b4 \ud14c\uc2a4\ud2b8'));
});

test(
'invokeOperation should handle missing auth and appCheck tokens gracefully',
() async {
Expand Down
Loading