Skip to content

fix: preserve duplicate user properties with empty-string value - #161

Merged
robertsLando merged 1 commit into
mqttjs:masterfrom
spokodev:fix/user-property-empty-string-value
Jul 14, 2026
Merged

robertsLando merged 1 commit into
mqttjs:masterfrom
spokodev:fix/user-property-empty-string-value

Conversation

@spokodev

@spokodev spokodev commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

The MQTT 5 parser aggregates repeated User Properties sharing a name using a truthiness check on the previously stored value. An empty string is a valid zero-length UTF-8 string but is falsy, so a following occurrence of the same name takes the first-insert branch and overwrites it instead of appending — silently dropping the empty value and collapsing the array to a scalar.

Repro: parsing a PUBLISH carrying user properties a="" then a="b" yields { a: 'b' } instead of { a: ['', 'b'] }. generate emits both pairs correctly; only the parser loses data, so generate → parse is not a round-trip.

Use an explicit !== undefined presence check so every value is retained, per MQTT 5.0 §3.3.2.3.7 (a User Property name may appear more than once) and §1.5.4 (UTF-8 encoded strings may be zero length). Adds a regression test.

The MQTT 5 parser aggregated repeated User Properties sharing a name using
a truthiness check on the previously stored value. An empty string is a
valid zero-length UTF-8 string but is falsy, so a following occurrence of
the same name overwrote it via the else branch instead of appending,
silently dropping the empty value and collapsing the array to a scalar.

Use an explicit `!== undefined` presence check so every value is retained,
per MQTT 5.0 3.3.2.3.7 (a name may appear more than once) and 1.5.4
(UTF-8 strings may be zero length).
@robertsLando
robertsLando requested a review from mcollina July 9, 2026 12:37
@robertsLando
robertsLando merged commit dd17095 into mqttjs:master Jul 14, 2026
3 checks passed
@robertsLando

Copy link
Copy Markdown
Member

@mcollina release?

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.

2 participants