fix: clear utf8 remainder on base64 failure and allow malformed decode

Address CodeRabbit review feedback:
- Clear _utf8Remainder when base64 decode fails to prevent stale bytes
  from corrupting subsequent chunks
- Add allowMalformed: true to utf8.decode() so malformed bytes become
  U+FFFD instead of throwing FormatException and losing the entire chunk

Signed-off-by: wo0d <fengz181x@gmail.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
xiaobai@local 2026-04-13 15:37:58 +08:00
parent c48aec914b
commit b187756428

View file

@ -342,6 +342,7 @@ class TerminalModel with ChangeNotifier {
bytes = base64Decode(data);
} catch (e) {
// If base64 decode fails, treat as plain text
_utf8Remainder.clear();
_writeToTerminal(data);
return;
}
@ -365,7 +366,7 @@ class TerminalModel with ChangeNotifier {
}
if (split > 0) {
final text = utf8.decode(bytes.sublist(0, split));
final text = utf8.decode(bytes.sublist(0, split), allowMalformed: true);
_writeToTerminal(text);
}
} catch (e) {