Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jun 14, 2024

Conversation

ysfscream
Copy link
Member

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?

  • Yes
  • No

Specific Instructions

None.

Other information

The updated function now:

  • Checks if format is specified and applies format conversion only if necessary.
  • Ensures messages already Buffer are not converted to strings and back to buffers, preserving data integrity.
  • Separates the logic into clearly defined functions for better readability and maintenance.

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

@ysfscream ysfscream added enhancement New feature or request fix Fix bug or issues CLI MQTTX CLI labels Jun 14, 2024
@ysfscream ysfscream added this to the v1.10.1 milestone Jun 14, 2024
@ysfscream ysfscream self-assigned this Jun 14, 2024
@Red-Asuka Red-Asuka merged commit 6346d57 into main Jun 14, 2024
5 checks passed
@Red-Asuka Red-Asuka deleted the ysf/cli branch June 14, 2024 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLI MQTTX CLI enhancement New feature or request fix Fix bug or issues
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants