⚠️ Potential issue | 🟠 Major
Fix IPv6 formatting in host_with_port.
format!("{}:{}", hostname, port) produces invalid strings for IPv6 hosts (e.g., ::1:8545). Bracket IPv6 addresses to avoid connection errors.
🐛 Proposed fix
pub fn host_with_port(&self) -> String {
- format!("{}:{}", self.hostname(), self.port())
+ let host = self.hostname();
+ if host.contains(':') {
+ format!("[{}]:{}", host, self.port())
+ } else {
+ format!("{}:{}", host, self.port())
+ }
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
pub fn host_with_port(&self) -> String {
let host = self.hostname();
if host.contains(':') {
format!("[{}]:{}", host, self.port())
} else {
format!("{}:{}", host, self.port())
}
}
🤖 Prompt for AI Agents
In `@crates/config/src/rpc.rs` around lines 77 - 90, The host_with_port() helper
currently formats "{hostname}:{port}" which breaks IPv6 addresses (e.g.,
"::1:8545"); update host_with_port() to detect IPv6 by checking hostname
returned from hostname() for ':' (and not already wrapped) and wrap it in square
brackets before appending the port so IPv6 becomes "[::1]:8545"; keep using the
existing hostname(), port() accessors and ensure you only add brackets when
necessary to avoid double-bracketing.
Originally posted by @coderabbitai[bot] in #1153 (comment)
Fix IPv6 formatting in
host_with_port.format!("{}:{}", hostname, port)produces invalid strings for IPv6 hosts (e.g.,::1:8545). Bracket IPv6 addresses to avoid connection errors.🐛 Proposed fix
pub fn host_with_port(&self) -> String { - format!("{}:{}", self.hostname(), self.port()) + let host = self.hostname(); + if host.contains(':') { + format!("[{}]:{}", host, self.port()) + } else { + format!("{}:{}", host, self.port()) + } }📝 Committable suggestion
🤖 Prompt for AI Agents
Originally posted by @coderabbitai[bot] in #1153 (comment)