mirror of
https://codeberg.org/icewind/nextcloud-config-parser.git
synced 2026-06-03 08:34:13 +02:00
fix non-port ipv6
This commit is contained in:
parent
f9650877ea
commit
20d09d186d
3 changed files with 23 additions and 3 deletions
22
src/lib.rs
22
src/lib.rs
|
|
@ -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"));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue