File tree Expand file tree Collapse file tree
crates/soroban-test/tests/it Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -212,4 +212,8 @@ fn message_sign_escapes_control_characters_in_preview() {
212212 !stderr. contains( '\x1b' ) ,
213213 "stderr should not contain raw ESC bytes, got: {stderr:?}"
214214 ) ;
215+ assert ! (
216+ stderr. contains( "\\ x1b" ) ,
217+ "stderr should contain escaped ESC as \\ x1b, got: {stderr:?}"
218+ ) ;
215219}
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ use crate::{
99 config:: { locator, secret} ,
1010 print:: Print ,
1111 signer:: { self , Signer } ,
12- utils:: strip_control_escapes ,
12+ utils:: escape_control_characters ,
1313} ;
1414
1515use super :: SEP53_PREFIX ;
@@ -93,7 +93,7 @@ impl Cmd {
9393 } ;
9494 print. infoln ( format ! (
9595 "Message: {}" ,
96- strip_control_escapes ( & message_display)
96+ escape_control_characters ( & message_display)
9797 ) ) ;
9898 println ! ( "{signature_base64}" ) ;
9999 Ok ( ( ) )
Original file line number Diff line number Diff line change @@ -171,8 +171,20 @@ pub fn is_hex_string(s: &str) -> bool {
171171 s. chars ( ) . all ( |s| s. is_ascii_hexdigit ( ) )
172172}
173173
174- pub fn strip_control_escapes ( s : & str ) -> String {
175- s. chars ( ) . filter ( |c| !c. is_control ( ) ) . collect ( )
174+ pub fn escape_control_characters ( s : & str ) -> String {
175+ use std:: fmt:: Write as _;
176+ let mut result = String :: with_capacity ( s. len ( ) ) ;
177+ for c in s. chars ( ) {
178+ if c. is_control ( ) {
179+ let mut buf = [ 0u8 ; 4 ] ;
180+ for & byte in c. encode_utf8 ( & mut buf) . as_bytes ( ) {
181+ write ! ( result, "\\ x{byte:02x}" ) . unwrap ( ) ;
182+ }
183+ } else {
184+ result. push ( c) ;
185+ }
186+ }
187+ result
176188}
177189
178190pub fn contract_id_hash_from_asset (
You can’t perform that action at this time.
0 commit comments