Skip to content

An open-source remote desktop application designed for self-hosting, as an alternative to TeamViewer.

fix: bracket a bare IPv6 ID server when deriving the API server (#16624)

Leo Camusbbffc1de5aa3
diff --git a/src/common.rs b/src/common.rs
index b9b690265..d00d94adf 100644
--- a/src/common.rs
+++ b/src/common.rs
@@ -1251,6 +1251,11 @@ fn get_api_server_(api: String, custom: String) -> String {
if !s0.is_empty() {
let s = crate::increase_port(&s0, -2);
if s == s0 {
+ let s = if hbb_common::is_ipv6_str(&s) && !s.starts_with('[') {
+ format!("[{s}]")
+ } else {
+ s
+ };
return format!("http://{}:{}", s, config::RENDEZVOUS_PORT - 2);
} else {
return format!("http://{}", s);
@@ -3209,6 +3214,14 @@ mod tests {
assert!(!is_public("https://[email protected]"));
}
+ #[test]
+ fn test_api_server_from_bare_ipv6_rendezvous_server() {
+ assert_eq!(
+ get_api_server_("".to_owned(), "2001:db8::1".to_owned()),
+ "http://[2001:db8::1]:21114"
+ );
+ }
+
#[test]
fn test_should_use_tcp_proxy_for_api_url() {
assert!(should_use_tcp_proxy_for_api_url(