Fix telnet_send_command_with_output returning the input#904
Open
Fix telnet_send_command_with_output returning the input#904
Conversation
telnet_send_command_with_output returns output with the original command contained. This leads to higher-level bugs. Fix #894 Also, change telnet_send_command_with_output to not return any "exit code" related output. This is now only part of telnet_send_command, which means this output does not leak into users of the DeviceConnection trait.
1 task
wgreenberg
requested changes
Feb 20, 2026
Collaborator
wgreenberg
left a comment
There was a problem hiding this comment.
haven't tested this yet, but i like the approach. just a few comments/questions
| command: &str, | ||
| wait_for_prompt: bool, | ||
| ) -> Result<String> { | ||
| debug_assert!(!command.contains('\n')); |
Collaborator
There was a problem hiding this comment.
why not assert!? afaik debug_assert should only be used when performance is an issue
| let response = String::from_utf8_lossy(&read_buf); | ||
| if response.contains("command done, exit code ") { | ||
| break; | ||
| if byte == b'\n' { |
Collaborator
There was a problem hiding this comment.
i'm not sure this will actually come up, but i think a consequence of doing byte-by-byte equality is if the output contains non-ASCII UTF-8 data, we may get a false positive on the newline check
| // | ||
| // 'TELNET' is quoted so that when the command gets echoed back, it does not match against | ||
| // RAYHUNTER_TELNET_COMMAND_DONE search string. | ||
| writer.write_all(format!("echo RAYHUNTER_'TELNET'_COMMAND_START; {command}; echo RAYHUNTER_'TELNET'_COMMAND_DONE\r\n").as_bytes()).await?; |
Collaborator
There was a problem hiding this comment.
this is a clever hack!
| let start = start + "RAYHUNTER_TELNET_COMMAND_START".len(); | ||
| string[start..end].trim_start_matches(['\r', '\n']) | ||
| } | ||
| _ => &string, |
Collaborator
There was a problem hiding this comment.
am i wrong in thinking we want to error out in this case?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
telnet_send_command_with_output returns output with the original command
contained. This leads to higher-level bugs. Fix #894
Also, change telnet_send_command_with_output to not return any "exit
code" related output. This is now only part of telnet_send_command,
which means this output does not leak into users of the DeviceConnection
trait (Which uses telnet_send_command_with_output)
telnet_send_commandis not a great API because users expect theexit code 0string to be part of output, but it's too widely used tochange it now.