Skip to content

Commit

Permalink
fix: cast --to-ascii does not work if input has trailing whitespaces (
Browse files Browse the repository at this point in the history
#8670)

* fix: `cast --to-ascii` removes trailing whitespaces on stdin

* fix: remove extra break line returned by `cast call`

* Update crates/cast/bin/main.rs

Co-authored-by: Matthias Seitz <[email protected]>

* Update crates/cast/src/lib.rs

Co-authored-by: DaniPopes <[email protected]>

* Update crates/cast/bin/main.rs

Co-authored-by: DaniPopes <[email protected]>

---------

Co-authored-by: Matthias Seitz <[email protected]>
Co-authored-by: DaniPopes <[email protected]>
  • Loading branch information
3 people authored Aug 14, 2024
1 parent 224fe9c commit 3e3b30c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion crates/cast/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ async fn main() -> Result<()> {
}
CastSubcommand::ToAscii { hexdata } => {
let value = stdin::unwrap(hexdata, false)?;
println!("{}", SimpleCast::to_ascii(&value)?);
println!("{}", SimpleCast::to_ascii(value.trim())?);
}
CastSubcommand::ToUtf8 { hexdata } => {
let value = stdin::unwrap(hexdata, false)?;
Expand Down
4 changes: 2 additions & 2 deletions crates/cast/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ where

// handle case when return type is not specified
Ok(if decoded.is_empty() {
format!("{res}\n")
res.to_string()
} else if json {
let tokens = decoded.iter().map(format_token_raw).collect::<Vec<_>>();
serde_json::to_string_pretty(&tokens).unwrap()
Expand Down Expand Up @@ -1503,7 +1503,7 @@ impl SimpleCast {
/// decoded[1].as_address().unwrap().to_string().to_lowercase(),
/// decoded[2].as_uint().unwrap().0.to_string(),
/// decoded[3].as_uint().unwrap().0.to_string(),
/// hex::encode(decoded[4].as_bytes().unwrap())
/// hex::encode(decoded[4].as_bytes().unwrap())
/// ]
/// .into_iter()
/// .collect::<Vec<_>>();
Expand Down

0 comments on commit 3e3b30c

Please sign in to comment.