This commit is contained in:
MengMengCode
2026-08-18 14:45:23 +08:00
parent fdb2ac45ce
commit 1df338f9b3
2 changed files with 24 additions and 0 deletions
+6
View File
@@ -852,7 +852,13 @@ func decodeUserData(
message.Text = string(utf16.Decode(units))
return nil
default:
// 8-bit (binary) user data has no portable text representation, so the
// raw payload bytes are rendered as uppercase hexadecimal after the user
// data header is stripped. This keeps the bubble non-empty and gives a
// faithful rendering of the delivered content rather than a blank "".
message.Encoding = SMSEncoding8BitPDU
payload := data[headerBytes:]
message.Text = strings.ToUpper(hex.EncodeToString(payload))
return nil
}
}
+18
View File
@@ -263,3 +263,21 @@ func TestParseCMGLPreservesUndecodableRecord(t *testing.T) {
t.Fatalf("messages = %#v", messages)
}
}
func TestDecode8BitPDUShowsHexPayload(t *testing.T) {
// SMS-DELIVER with no SMSC, from +12345, DCS=0xF5 (8-bit data,
// alphabet bits 0x0c), UDL=3. User data bytes are 0xAA 0xBB 0xCC.
// Built from the GSM-7 deliver vector by swapping the DCS to 0xF5
// and replacing the user data with three raw binary bytes.
message, err := decodeSMSPDU(
"000405912143F500F54210203040500003AABBCC",
)
if err != nil {
t.Fatalf("decode 8-bit: %v", err)
}
if message.Encoding != SMSEncoding8BitPDU ||
message.Text != "AABBCC" ||
message.RawUserData != "AABBCC" {
t.Fatalf("8-bit message = %#v", message)
}
}