From 1df338f9b31cb218f288ec6588800b14deb43173 Mon Sep 17 00:00:00 2001 From: MengMengCode <227010654+MengMengCode@users.noreply.github.com> Date: Tue, 18 Aug 2026 14:45:23 +0800 Subject: [PATCH] FIX #59 --- internal/device/sms_pdu.go | 6 ++++++ internal/device/sms_pdu_test.go | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/internal/device/sms_pdu.go b/internal/device/sms_pdu.go index ddb3db5..d627b12 100644 --- a/internal/device/sms_pdu.go +++ b/internal/device/sms_pdu.go @@ -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 } } diff --git a/internal/device/sms_pdu_test.go b/internal/device/sms_pdu_test.go index 405f17e..ffb926f 100644 --- a/internal/device/sms_pdu_test.go +++ b/internal/device/sms_pdu_test.go @@ -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) + } +}