Skip to content

Commit 674990b

Browse files
vilattometa-codesync[bot]
authored andcommitted
Anchor get_host_prefix regex to match Python behavior
Summary: Python re.match() anchors at the start of the string, but Rust Regex::captures() finds a match anywhere. This caused get_host_prefix() to return "c" for IPv6-style hostnames like "8c50-153b-..." on Sandcastle TW hosts, while Python correctly returned empty string. Add ^ anchor to the regex to match Python behavior. Reviewed By: genevievehelsel Differential Revision: D103090288 fbshipit-source-id: 9a34042a29c4ab7c5567bf0e24b678b9d5bc7967
1 parent eb7e1a4 commit 674990b

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

eden/fs/cli_rs/edenfs-utils/src/hostname.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub fn get_host_prefix(hostname: &str) -> String {
3737
//
3838
// Returns an empty string if no prefix is found.
3939

40-
let re = Regex::new(r"([a-zA-Z\-]+)\d+.*").unwrap();
40+
let re = Regex::new(r"^([a-zA-Z\-]+)\d+.*").unwrap();
4141
re.captures(hostname).map_or_else(String::new, |captures| {
4242
captures.get(1).unwrap().as_str().to_string()
4343
})
@@ -85,5 +85,9 @@ mod tests {
8585

8686
let mbp_prefix = get_host_prefix("helsel-mbp");
8787
assert_eq!(mbp_prefix, "");
88+
89+
let ipv6_style =
90+
get_host_prefix("8c50-153b-0004-0000.twshared63901.04.rva3.tw.fbinfra.net");
91+
assert_eq!(ipv6_style, "");
8892
}
8993
}

0 commit comments

Comments
 (0)