fix: support utf-16 encoding

Signed-off-by: The one with the braid <info@braid.business>
This commit is contained in:
The one with the braid 2025-04-04 09:22:32 +02:00
parent c1d9fa2db3
commit 0b52723667
No known key found for this signature in database
GPG key ID: 79D2235BC19FF56A
4 changed files with 20 additions and 22 deletions

View file

@ -1,5 +1,5 @@
variables:
FLUTTER_VERSION: 3.24.3
FLUTTER_VERSION: 3.29.2
image: registry.gitlab.com/theonewiththebraid/flutter-dockerimages:${FLUTTER_VERSION}-base

View file

@ -81,7 +81,7 @@ class PassBarcode {
return PassBarcode(
format: _allowedFormats[json['format']]!,
barcodeData:
Uint8List.fromList(messageEncoding.encode(json['message'] as String)),
Uint8List.fromList(messageEncoding.encode((json['message'] as String).replaceAll('\\', '\\\\'))),
messageEncoding: messageEncoding,
altText: json['altText'] as String?,
);

View file

@ -5,7 +5,6 @@ import 'package:archive/archive.dart';
import 'package:charset/charset.dart';
import 'package:crypto/crypto.dart';
import 'package:intl/locale.dart';
import 'package:pkpass/pkpass.dart';
import 'package:pkpass/pkpass/utils/file_matcher.dart';
import 'package:pkpass/pkpass/utils/lproj_parser.dart';
@ -36,7 +35,10 @@ class PassFile {
final file = archive.files
.singleWhere((element) => element.name == manifestEntry.key);
final content = file.byteContent;
final content = file.readBytes();
if (content == null) {
return;
}
String hash = sha1.convert(content).toString();
@ -80,7 +82,7 @@ class PassFile {
);
if (path == null) return null;
final file = _folder.singleWhere((element) => element.name == path);
final content = file.byteContent;
final content = file.readBytes();
return content;
}
@ -119,29 +121,25 @@ class PassFile {
extension on ArchiveFile {
String get stringContent {
final codec = Charset.detect(
byteContent,
readBytes()!,
defaultEncoding: utf8,
orders: [
utf8,
ascii,
gbk,
latin1,
utf16,
],
) ??
utf8;
return codec.decode(content);
}
Uint8List get byteContent {
decompress();
final content = this.content;
if (content is String) {
return utf8.encode(content);
} else if (content is Iterable) {
return Uint8List.fromList(content.cast<int>().toList());
} else {
return rawContent!.toUint8List();
try {
return codec.decode(content);
} on FormatException {
// utf8 and utf16 are hard to distinguish
if (codec is Utf8Codec) {
return utf16.decode(content);
}
rethrow;
}
}
}

View file

@ -1,6 +1,6 @@
name: pkpass
description: A Dart native passbook parsing library supporting checksum verification, barcode parsing, localization and much more.
version: 2.1.4
version: 2.2.0
repository: https://gitlab.com/TheOneWithTheBraid/dart_pkpass.git
homepage: https://gitlab.com/TheOneWithTheBraid/dart_pkpass
issue_tracker: https://gitlab.com/TheOneWithTheBraid/dart_pkpass/-/issues
@ -12,7 +12,7 @@ environment:
sdk: ^3.4.0
dependencies:
archive: ^3.3.7
archive: ^4.0.5
barcode: ^2.2.4
charset: ^2.0.1
crypto: ^3.0.3
@ -27,5 +27,5 @@ topics:
dev_dependencies:
import_sorter: ^4.6.0
lints: ^5.0.0
lints: ^6.0.0
test: ^1.21.0