From 0b5272366710a339b3f3c919f761786a92bac111 Mon Sep 17 00:00:00 2001 From: The one with the braid Date: Fri, 4 Apr 2025 09:22:32 +0200 Subject: [PATCH 1/4] fix: support utf-16 encoding Signed-off-by: The one with the braid --- .gitlab-ci.yml | 2 +- lib/pkpass/models/barcode.dart | 2 +- lib/pkpass/pass_file.dart | 32 +++++++++++++++----------------- pubspec.yaml | 6 +++--- 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index dde3240..fc8cc2c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -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 diff --git a/lib/pkpass/models/barcode.dart b/lib/pkpass/models/barcode.dart index 83bc06a..63a8a17 100644 --- a/lib/pkpass/models/barcode.dart +++ b/lib/pkpass/models/barcode.dart @@ -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?, ); diff --git a/lib/pkpass/pass_file.dart b/lib/pkpass/pass_file.dart index c0a4578..3c93fd1 100644 --- a/lib/pkpass/pass_file.dart +++ b/lib/pkpass/pass_file.dart @@ -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().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; } } } diff --git a/pubspec.yaml b/pubspec.yaml index c442e86..1b08fd3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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 From bc8e56d59d6e2d73933c00642eeba2044b6c328c Mon Sep 17 00:00:00 2001 From: The one with the braid Date: Fri, 4 Apr 2025 09:24:25 +0200 Subject: [PATCH 2/4] chore: update changelog Signed-off-by: The one with the braid --- .gitlab-ci.yml | 2 +- CHANGELOG.md | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index fc8cc2c..e43f027 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,7 +1,7 @@ variables: FLUTTER_VERSION: 3.29.2 -image: registry.gitlab.com/theonewiththebraid/flutter-dockerimages:${FLUTTER_VERSION}-base +image: registry.gitlab.com/polycule_client/flutter-dockerimages:${FLUTTER_VERSION}-base stages: - coverage diff --git a/CHANGELOG.md b/CHANGELOG.md index cb6b0ef..7a86379 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## v2.2.0 + +- fix: support utf-16 encoding (The one with the braid) + ## v2.1.4 - chore: bump SDK From d34546b8bcdeaeb34ba5c7e8283a773fec295efc Mon Sep 17 00:00:00 2001 From: The one with the braid Date: Fri, 4 Apr 2025 09:27:57 +0200 Subject: [PATCH 3/4] fix: codestyle Signed-off-by: The one with the braid --- lib/pkpass/models/barcode.dart | 6 ++++-- lib/pkpass/pass_file.dart | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/pkpass/models/barcode.dart b/lib/pkpass/models/barcode.dart index 63a8a17..6035e90 100644 --- a/lib/pkpass/models/barcode.dart +++ b/lib/pkpass/models/barcode.dart @@ -80,8 +80,10 @@ class PassBarcode { supportedCodecs[(json['messageEncoding'] as String).toLowerCase()]!; return PassBarcode( format: _allowedFormats[json['format']]!, - barcodeData: - Uint8List.fromList(messageEncoding.encode((json['message'] as String).replaceAll('\\', '\\\\'))), + barcodeData: Uint8List.fromList( + messageEncoding + .encode((json['message'] as String).replaceAll('\\', '\\\\')), + ), messageEncoding: messageEncoding, altText: json['altText'] as String?, ); diff --git a/lib/pkpass/pass_file.dart b/lib/pkpass/pass_file.dart index 3c93fd1..4a1386b 100644 --- a/lib/pkpass/pass_file.dart +++ b/lib/pkpass/pass_file.dart @@ -5,6 +5,7 @@ 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'; From 17fbf8da337b9b769c4b6eb1602345270fbc0504 Mon Sep 17 00:00:00 2001 From: The one with the braid Date: Fri, 4 Apr 2025 10:07:18 +0200 Subject: [PATCH 4/4] fix: pubspec Signed-off-by: The one with the braid --- pubspec.yaml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pubspec.yaml b/pubspec.yaml index 1b08fd3..7d558a9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -7,7 +7,6 @@ issue_tracker: https://gitlab.com/TheOneWithTheBraid/dart_pkpass/-/issues funding: - https://www.buymeacoffee.com/braid - environment: sdk: ^3.4.0 @@ -19,7 +18,6 @@ dependencies: http: ^1.0.0 intl: ">=0.17.0 <1.0.0" - topics: - wallet - pkpass @@ -27,5 +25,5 @@ topics: dev_dependencies: import_sorter: ^4.6.0 - lints: ^6.0.0 + lints: ^5.0.0 test: ^1.21.0