Ignore UserComment in EXIF

This commit is contained in:
Ming Ming 2021-10-25 15:25:52 +08:00
parent 4ac8cac73d
commit 9b9e737a95
2 changed files with 21 additions and 2 deletions

View file

@ -30,7 +30,9 @@ class Exif with EquatableMixin {
JsonObj toJson() {
return Map.fromEntries(
data.entries.where((e) => e.key != "MakerNote").map((e) {
data.entries
.where((e) => e.key != "MakerNote" && e.key != "UserComment")
.map((e) {
dynamic jsonValue;
if (e.value is Rational) {
jsonValue = e.value.toJson();
@ -55,7 +57,10 @@ class Exif with EquatableMixin {
// we are filtering out MakerNote here because it's generally very large
// and could exceed the 1MB cursor size limit on Android. Second, the
// content is proprietary and thus useless to us anyway
json.entries.where((e) => e.key != "MakerNote").map((e) {
// UserComment is now also ignored as its size could be very large
json.entries
.where((e) => e.key != "MakerNote" && e.key != "UserComment")
.map((e) {
dynamic exifValue;
if (e.value is Map) {
exifValue = Rational.fromJson(e.value.cast<String, dynamic>());

View file

@ -111,6 +111,13 @@ void main() {
});
expect(exif.toJson(), <String, dynamic>{});
});
test("UserComment", () {
final exif = Exif(<String, dynamic>{
"UserComment": Uint8List.fromList([0x00, 0x33, 0x66, 0x99, 0xCC, 0xFF]),
});
expect(exif.toJson(), <String, dynamic>{});
});
});
group("fromJson", () {
@ -175,6 +182,13 @@ void main() {
};
expect(Exif.fromJson(json), Exif(<String, dynamic>{}));
});
test("UserComment", () {
final json = <String, dynamic>{
"UserComment": [1],
};
expect(Exif.fromJson(json), Exif(<String, dynamic>{}));
});
});
});
}