emqx / MQTTX

A Powerful and All-in-One MQTT 5.0 client toolbox for Desktop, CLI and WebSocket.
https://mqttx.app
Apache License 2.0
3.64k stars 428 forks source link

fix(cli): correct data conversion for publishing messages with format #1695

Closed ysfscream closed 3 weeks ago

ysfscream commented 3 weeks ago

What is the current behavior?

When publishing a message using the mqttx pub command with the format option specified, the received data differs from the original data. This issue occurs because the data read from a file is already a Buffer. However, the conversion process unnecessarily converts it to a string and back to a Buffer, causing data corruption.

Issue Number

Example: #1692 #1694

What is the new behavior?

The new behavior ensures that unnecessary conversions are avoided when a message is read from a file and the format option is specified. The convertPayload function now correctly handles the binary format without additional transformations. This fix ensures the integrity of the data during the publishing process.

Does this PR introduce a breaking change?

Specific Instructions

None.

Other information

The updated function now:

Reviewed and tested to ensure the input and output messages are entirely identical.