Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/crates/soroban-test/tests/it/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,8 @@ fn message_sign_escapes_control_characters_in_preview() {
!stderr.contains('\x1b'),
"stderr should not contain raw ESC bytes, got: {stderr:?}"
);
assert!(
stderr.contains("\\x1b"),
"stderr should contain escaped ESC as \\x1b, got: {stderr:?}"
);
}
4 changes: 2 additions & 2 deletions cmd/soroban-cli/src/commands/message/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
config::{locator, secret},
print::Print,
signer::{self, Signer},
utils::strip_control_escapes,
utils::escape_control_characters,
};

use super::SEP53_PREFIX;
Expand Down Expand Up @@ -93,7 +93,7 @@ impl Cmd {
};
print.infoln(format!(
"Message: {}",
strip_control_escapes(&message_display)
escape_control_characters(&message_display)
));
println!("{signature_base64}");
Ok(())
Expand Down
16 changes: 14 additions & 2 deletions cmd/soroban-cli/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,20 @@ pub fn is_hex_string(s: &str) -> bool {
s.chars().all(|s| s.is_ascii_hexdigit())
}

pub fn strip_control_escapes(s: &str) -> String {
s.chars().filter(|c| !c.is_control()).collect()
pub fn escape_control_characters(s: &str) -> String {
use std::fmt::Write as _;
let mut result = String::with_capacity(s.len());
for c in s.chars() {
if c.is_control() {
let mut buf = [0u8; 4];
for &byte in c.encode_utf8(&mut buf).as_bytes() {
write!(result, "\\x{byte:02x}").unwrap();
}
} else {
result.push(c);
}
}
result
}

Comment thread
fnando marked this conversation as resolved.
pub fn contract_id_hash_from_asset(
Expand Down
Loading