mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-22 23:54:33 +01:00
fix: log SJIS decoding errors instead of silently discarding them
Add SJISToUTF8Lossy() that wraps SJISToUTF8() and logs decode errors at slog.Debug level. Replace all 31 call sites across 17 files that previously discarded the error with `_, _ =`. This makes garbled text from malformed SJIS client data debuggable without adding noise at default log levels.
This commit is contained in:
@@ -461,6 +461,25 @@ func BenchmarkCSVElems(b *testing.B) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSJISToUTF8Lossy(t *testing.T) {
|
||||
// Valid SJIS (ASCII subset) decodes correctly.
|
||||
got := SJISToUTF8Lossy([]byte("Hello"))
|
||||
if got != "Hello" {
|
||||
t.Errorf("SJISToUTF8Lossy(valid) = %q, want %q", got, "Hello")
|
||||
}
|
||||
|
||||
// Truncated multi-byte SJIS sequence (lead byte 0x82 without trail byte)
|
||||
// does not panic and returns some result (lossy).
|
||||
got = SJISToUTF8Lossy([]byte{0x82})
|
||||
_ = got // must not panic
|
||||
|
||||
// Nil input returns empty string.
|
||||
got = SJISToUTF8Lossy(nil)
|
||||
if got != "" {
|
||||
t.Errorf("SJISToUTF8Lossy(nil) = %q, want %q", got, "")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUTF8ToSJIS_UnsupportedCharacters(t *testing.T) {
|
||||
// Regression test for PR #116: Characters outside the Shift-JIS range
|
||||
// (e.g. Lenny face, cuneiform) previously caused a panic in UTF8ToSJIS,
|
||||
|
||||
Reference in New Issue
Block a user