fix non-port ipv6

This commit is contained in:
Robin Appelman 2026-03-06 13:20:56 +01:00
commit 20d09d186d
3 changed files with 23 additions and 3 deletions

2
Cargo.lock generated
View file

@ -797,7 +797,7 @@ dependencies = [
[[package]]
name = "nextcloud-config-parser"
version = "0.15.1"
version = "0.15.2"
dependencies = [
"form_urlencoded",
"indexmap",

View file

@ -1,7 +1,7 @@
[package]
name = "nextcloud-config-parser"
description = "Rust parser for nextcloud config files"
version = "0.15.1"
version = "0.15.2"
authors = ["Robin Appelman <robin@icewind.nl>"]
edition = "2021"
license = "MIT OR Apache-2.0"

View file

@ -348,7 +348,15 @@ fn split_host(host: &str) -> (&str, Option<u16>, Option<&str>) {
if host.starts_with('/') {
return ("localhost", None, Some(host));
}
let (host, port_or_socket) = host.rsplit_once(':').unwrap_or((host, ""));
let (host, port_or_socket) = if host.starts_with('[') {
if let Some(pos) = host.rfind("]:") {
(&host[0..pos + 1], &host[pos + 2..])
} else {
(host, "")
}
} else {
host.rsplit_once(':').unwrap_or((host, ""))
};
if port_or_socket.is_empty() {
return (host, None, None);
}
@ -357,3 +365,15 @@ fn split_host(host: &str) -> (&str, Option<u16>, Option<&str>) {
Err(_) => (host, None, Some(port_or_socket)),
}
}
#[test]
fn test_spit_host() {
assert_eq!(("localhost", None, None), split_host("localhost"));
assert_eq!(("localhost", Some(123), None), split_host("localhost:123"));
assert_eq!(
("localhost", None, Some("foo")),
split_host("localhost:foo")
);
assert_eq!(("[::1]", None, None), split_host("[::1]"));
assert_eq!(("[::1]", Some(123), None), split_host("[::1]:123"));
}