fix: replace String.fromCharCodes with utf8.decode for proper Chinese character handling in JSON import (#874)

This commit is contained in:
lollipopkit🏳️‍⚧️
2025-08-31 20:06:47 +08:00
committed by GitHub
parent 12a243d139
commit 4c369546da

View File

@@ -360,7 +360,13 @@ final class _BackupPageState extends ConsumerState<BackupPage> with AutomaticKee
onTap: () async { onTap: () async {
final data = await context.showImportDialog(title: l10n.snippet, modelDef: Snippet.example.toJson()); final data = await context.showImportDialog(title: l10n.snippet, modelDef: Snippet.example.toJson());
if (data == null) return; 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( final (list, _) = await context.showLoadingDialog(
fn: () => Computer.shared.start((s) { fn: () => Computer.shared.start((s) {
return json.decode(s) as List; return json.decode(s) as List;
@@ -588,7 +594,13 @@ extension on _BackupPageState {
void _onBulkImportServers(BuildContext context) async { void _onBulkImportServers(BuildContext context) async {
final data = await context.showImportDialog(title: l10n.server, modelDef: Spix.example.toJson()); final data = await context.showImportDialog(title: l10n.server, modelDef: Spix.example.toJson());
if (data == null) return; 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 { try {
final (spis, err) = await context.showLoadingDialog( final (spis, err) = await context.showLoadingDialog(