fix(xep): Fix parsing user avatar data with newlines
This commit is contained in:
parent
88545e3308
commit
f2d8c6a009
@ -16,6 +16,7 @@ abstract class AvatarError {}
|
|||||||
|
|
||||||
class UnknownAvatarError extends AvatarError {}
|
class UnknownAvatarError extends AvatarError {}
|
||||||
|
|
||||||
|
/// The result of a successful query of a users avatar.
|
||||||
class UserAvatarData {
|
class UserAvatarData {
|
||||||
const UserAvatarData(this.base64, this.hash);
|
const UserAvatarData(this.base64, this.hash);
|
||||||
|
|
||||||
@ -26,7 +27,9 @@ class UserAvatarData {
|
|||||||
final String hash;
|
final String hash;
|
||||||
|
|
||||||
/// The raw avatar data.
|
/// 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 {
|
class UserAvatarMetadata {
|
||||||
|
14
packages/moxxmpp/test/xeps/xep_0084_test.dart
Normal file
14
packages/moxxmpp/test/xeps/xep_0084_test.dart
Normal 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');
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user