emqx / CocoaMQTT

MQTT 5.0 client library for iOS and macOS written in Swift
https://www.emqx.com/en
Other
1.6k stars 420 forks source link

Bugfix: Publishing a message: userProperty key is ignored, causing connection termination #564

Closed nicolasanjoran closed 11 months ago

nicolasanjoran commented 11 months ago

When publishing a message with user properties, keys of those properties are ignored. This is causing issues (tested with emqx/emqx:5.3.0), the broker terminates the connection.

Code to reproduce the issue:

// Connect to your MQTT 5 broker first...

// Then publish a message with user properties
let props = MqttPublishProperties()
props.userProperty = ["test":"userprop", "test2": "userprop2"]
mqtt5.publish("chat/test", withString: "id:123", properties: props)

Error logs:

didPublishMessage: CocoaMQTT5Message(topic: chat/test, qos: qos0, payload: [105, 100, 58, 49, 50, 51])
didDisconnect: Optional(Error Domain=MGCDAsyncSocketErrorDomain Code=7 "Socket closed by remote peer" UserInfo={NSLocalizedDescription=Socket closed by remote peer})

I found that both the key.bytesWithLength and value.bytesWithLength need to be concatenated.

I tested the fix against emqx/emqx:5.3.0.

Thanks 😊

leeway1208 commented 11 months ago

thank you for your support~~~