Skip to content

Fix message encode crash, DCS-aware decode, and user-defined TLV round-trip#261

Open
fdciabdul wants to merge 1 commit into
farhadi:masterfrom
fdciabdul:fix/encoding-tlv-and-crashes
Open

Fix message encode crash, DCS-aware decode, and user-defined TLV round-trip#261
fdciabdul wants to merge 1 commit into
farhadi:masterfrom
fdciabdul:fix/encoding-tlv-and-crashes

Conversation

@fdciabdul

Copy link
Copy Markdown

@
This PR fixes three independent, frequently-reported issues. Each change is small and covered by a regression test (test/fixes.js). No API changes.

short_message encode crash — fixes #229, #256

filters.message.encode assumed a string or {message} object and threw
TypeError: Cannot read properties of undefined (reading message) when given a
number, null, or undefined short_message. It now coerces scalars and guards
null/undefined.

Wrong/empty decode for high Data Coding Scheme values — fixes #66, #252

Decoding used data_coding & 0x0F, which mis-detects the charset whenever the DCS
high nibble carries message-class / MWI / compression bits (GSM 03.38). Decoding
now parses the full DCS byte. Low data_coding values (0x00–0x0E) are unchanged.

User-defined TLVs not sent — fixes #231

Unknown/custom TLVs addressed by their numeric tag id (e.g. pdu[0x3C02] = Buffer.from(...))
were parsed on decode but silently dropped on encode. They now round-trip: the PDU
constructor keeps numeric-tag keys and toBuffer() writes them.

Tests

Adds test/fixes.js. All existing tests still pass (the only failure in CI-less
local runs is the pre-existing network-dependent invalid-host DNS test).


These fixes are also available, alongside a full TypeScript rewrite (dual ESM+CJS,
types, Bun support) and more features, in the maintained fork
https://github.com/fdciabdul/node-smpp-next — but this PR intentionally keeps the
changes minimal and JS-only for easy review/merge here.
@

@
fix: message encode crash, DCS-aware decode, user-defined TLV round-trip

- farhadi#229/farhadi#256: tolerate non-string short_message (number/null/undefined) in the
  message encode filter instead of throwing
  "Cannot read properties of undefined (reading message)"
- farhadi#66/farhadi#252: resolve decode charset from the full Data Coding Scheme byte
  (GSM 03.38 message-class / MWI groups) instead of the naive low-nibble mask
- farhadi#231: user-defined / unknown TLVs addressed by numeric tag id now round-trip
  on encode (PDU constructor + toBuffer), not only on decode

Adds regression tests (test/fixes.js).
@
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.

Support for user-defined TLVs Crash when short_message misstype message.decode() incorrect detects encoding

1 participant