fix(xep): Fix parsing user avatar data with newlines

This commit is contained in:
PapaTutuWawa 2023-06-10 21:06:30 +02:00
parent 88545e3308
commit f2d8c6a009
2 changed files with 18 additions and 1 deletions

View File

@ -16,6 +16,7 @@ abstract class AvatarError {}
class UnknownAvatarError extends AvatarError {}
/// The result of a successful query of a users avatar.
class UserAvatarData {
const UserAvatarData(this.base64, this.hash);
@ -26,7 +27,9 @@ class UserAvatarData {
final String hash;
/// The raw avatar data.
List<int> get data => base64Decode(base64);
/// NOTE: Remove newlines because "Line feeds SHOULD NOT be added but MUST be accepted"
/// (https://xmpp.org/extensions/xep-0084.html#proto-data).
List<int> get data => base64Decode(base64.replaceAll('\n', ''));
}
class UserAvatarMetadata {

View File

@ -0,0 +1,14 @@
import 'dart:convert';
import 'package:moxxmpp/moxxmpp.dart';
import 'package:test/test.dart';
void main() {
test('Test accepting newlines', () {
const data = UserAvatarData(
'cGFwYXR1d\nHV3\n\nYXdh',
'some-id',
);
expect(utf8.decode(data.data), 'papatutuwawa');
});
}