Skip to content

fix(ui): refactor terminal output handling for UTF-8 and SSE consistency#19

Merged
linletian merged 1 commit intodevelopfrom
fix/refresh-prob-1
Mar 13, 2026
Merged

fix(ui): refactor terminal output handling for UTF-8 and SSE consistency#19
linletian merged 1 commit intodevelopfrom
fix/refresh-prob-1

Conversation

@linletian
Copy link
Owner

Summary

修复 PR #18 合并后遗留的两个前端缺陷:

  1. UTF-8 多字节字符跨帧损坏 - WebSocket 二进制路径对每个帧独立解码会导致 UTF-8 字符被分割时损坏
  2. SSE 回退路径绕过过滤逻辑 - SSE 路径直接写入 chunk,跳过了终端响应过滤

Changes

  • 新增 sanitizeTerminalOutput() 统一终端输出过滤逻辑
  • 新增 decodeTTYOutputChunk() 使用持久化 TextDecoder 实现流式 UTF-8 解码
  • 新增 resetTTYOutputDecoder() 在连接断开时重置解码器状态
  • 重构 loadLog(), loadLogSince(), WebSocket handlers 使用统一的输出函数

Testing

  • go test ./... 通过
  • gofmt -l . 无格式化问题
  • ✅ 双二进制构建成功

Related

  • docs/pr18-fix-plan.md - 原始修复计划文档
  • docs/TERMINAL_FILTER_REVIEW.md - 终端过滤实现指南
  • docs/TERMINAL_IO_ANALYSIS.md - 终端 I/O 架构分析

- Add sanitizeTerminalOutput() to centralize response filtering
- Add decodeTTYOutputChunk() with persistent TextDecoder for stream-safe UTF-8 decoding
- Route SSE fallback through same sanitization as WebSocket path
- Reset decoder state on disconnect to prevent state leakage

Fixes two defects in PR #18:
1. UTF-8 multibyte characters could be corrupted when split across WebSocket frames
2. SSE fallback bypassed response filtering, allowing garbage strings to leak

No behavioral changes to terminal protocol or filtering rules.

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
@linletian linletian merged commit ec8b75f into develop Mar 13, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant