From 4c369546da26c1d2b37323f81edda65600dd88cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?lollipopkit=F0=9F=8F=B3=EF=B8=8F=E2=80=8D=E2=9A=A7?= =?UTF-8?q?=EF=B8=8F?= <10864310+lollipopkit@users.noreply.github.com> Date: Sun, 31 Aug 2025 20:06:47 +0800 Subject: [PATCH] fix: replace String.fromCharCodes with utf8.decode for proper Chinese character handling in JSON import (#874) --- lib/view/page/backup.dart | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/view/page/backup.dart b/lib/view/page/backup.dart index ee71a2d0..cec6a5d9 100644 --- a/lib/view/page/backup.dart +++ b/lib/view/page/backup.dart @@ -360,7 +360,13 @@ final class _BackupPageState extends ConsumerState with AutomaticKee onTap: () async { final data = await context.showImportDialog(title: l10n.snippet, modelDef: Snippet.example.toJson()); if (data == null) return; - final str = String.fromCharCodes(data); + String str; + try { + str = utf8.decode(data); + } on FormatException catch (e, s) { + context.showErrDialog(e, s, libL10n.error); + return; + } final (list, _) = await context.showLoadingDialog( fn: () => Computer.shared.start((s) { return json.decode(s) as List; @@ -588,7 +594,13 @@ extension on _BackupPageState { void _onBulkImportServers(BuildContext context) async { final data = await context.showImportDialog(title: l10n.server, modelDef: Spix.example.toJson()); if (data == null) return; - final text = String.fromCharCodes(data); + String text; + try { + text = utf8.decode(data); + } on FormatException catch (e, s) { + context.showErrDialog(e, s, libL10n.error); + return; + } try { final (spis, err) = await context.showLoadingDialog(