Eppiehu opened a new issue, #11413:
URL: https://github.com/apache/rocketmq/issues/11413

   ### Before Creating the Bug Report
   
   - [x] I found a bug in this repository rather than a support question.
   - [x] I searched existing Issues and PRs and did not find the same fix.
   - [x] I confirmed that this issue belongs to apache/rocketmq.
   
   ### Runtime platform environment
   
   Windows 11, PowerShell, Maven 3.9.16.
   
   ### RocketMQ version
   
   5.5.1, develop. The affected production file was checked against the current 
official develop branch.
   
   ### JDK Version
   
   Eclipse Temurin OpenJDK 17.0.19.
   
   ### Describe the Bug
   
   
[`SendMessageCommand.execute`](https://github.com/apache/rocketmq/blob/develop/tools/src/main/java/org/apache/rocketmq/tools/command/message/SendMessageCommand.java#L94)
 calls `trim()` on the `-p/--body` value before encoding it as UTF-8. This 
removes leading and trailing whitespace from the message payload. A 
whitespace-only non-empty body is also converted into an empty byte array.
   
   ### Steps to Reproduce
   
   The issue can be reproduced with a command-level test using a mocked 
`DefaultMQProducer`, without a running NameServer or Broker:
   
   1. Parse the arguments `{"-t", "mytopic", "-p", "\t message \r\n"}` using 
`SendMessageCommand.buildCommandlineOptions` and `DefaultParser`.
   2. Execute the command and capture the `Message` passed to `producer.send`.
   3. Compare the captured body with the input string's UTF-8 bytes.
   
   The assertion fails on the existing code: the expected body length is 12 
bytes, but the captured body is 7 bytes (`message`).
   
   Both the normal and explicit target queue send paths share this body 
construction.
   
   ### What Did You Expect to See?
   
   The message body should exactly preserve the UTF-8 bytes of the caller's 
`-p` value, including leading and trailing whitespace.
   
   ### What Did You See Instead?
   
   Leading and trailing payload whitespace is removed.
   
   ### Additional Context
   
   I have prepared a one-line fix and regression tests for leading/trailing 
whitespace (including tabs and newlines), whitespace-only bodies, an explicit 
target queue with UTF-8 content, and ordinary bodies. The tests use an isolated 
mocked producer.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to