Skip to content

Commit ad5e3b5

Browse files
igorlinemikelodder7
authored andcommitted
fix: add $ to suffix regex to ensure wallet address ending with specified hex string (foundry-rs#5802)
1 parent d3637ea commit ad5e3b5

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

crates/cast/bin/cmd/create2.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,10 @@ impl Create2Args {
9696
));
9797
}
9898
if let Some(suffix) = ends_with {
99-
regexs.push(
100-
(get_regex_hex_string(suffix).wrap_err("invalid suffix hex provided")?).to_string(),
101-
);
99+
regexs.push(format!(
100+
r"{}$",
101+
get_regex_hex_string(suffix).wrap_err("invalid prefix hex provided")?
102+
))
102103
}
103104

104105
debug_assert!(
@@ -204,6 +205,14 @@ mod tests {
204205

205206
assert!(address.starts_with("aaa"));
206207

208+
// odd hex chars with 0x suffix
209+
let args = Create2Args::parse_from(["foundry-cli", "--ends-with", "bb"]);
210+
let create2_out = args.run().unwrap();
211+
let address = create2_out.address;
212+
let address = format!("{address:x}");
213+
214+
assert!(address.ends_with("bb"));
215+
207216
// check fails on wrong chars
208217
let args = Create2Args::parse_from(["foundry-cli", "--starts-with", "0xerr"]);
209218
let create2_out = args.run();

0 commit comments

Comments
 (0)