From e17549c508fed7e52c13c8a75db35632ffd76724 Mon Sep 17 00:00:00 2001 From: Admin Date: Fri, 17 Jul 2026 12:45:34 +0000 Subject: [PATCH] docs: add detailed comment for UTF-8 charset fix --- internal/captcha/handler.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/captcha/handler.go b/internal/captcha/handler.go index 831f0d9..eb7461b 100644 --- a/internal/captcha/handler.go +++ b/internal/captcha/handler.go @@ -422,7 +422,10 @@ func decodeMathFromOutput(output []float32) string { } // 字符集:索引 1-18 对应字符 - // 注意:使用 slice 而不是 string,避免 UTF-8 多字节字符的索引问题 + // 【关键修复】使用 string slice 而不是 string,避免 UTF-8 多字节字符的索引错位问题 + // Go 的 string 是 UTF-8 编码,for range 迭代时 i 是字节位置而非字符位置 + // 模型输出的索引是按字符位置(1-18),直接用 string[idx-1] 访问多字节字符会错位 + // 例如:÷ (U+00F7, 2字节) 和 × (U+00D7, 2字节) 会导致后续字符索引跳跃 CHARS := []string{"", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+", "-", "*", "/", "÷", "×", "=", "?"} // DEBUG: 打印字符集