mirror of
https://codeberg.org/icewind/nextcloud-config-parser.git
synced 2026-06-03 08:34:13 +02:00
fix ipv6 database host
This commit is contained in:
parent
f694ccb408
commit
70543db580
3 changed files with 54 additions and 9 deletions
16
src/lib.rs
16
src/lib.rs
|
|
@ -348,14 +348,12 @@ fn split_host(host: &str) -> (&str, Option<u16>, Option<&str>) {
|
|||
if host.starts_with('/') {
|
||||
return ("localhost", None, Some(host));
|
||||
}
|
||||
let mut parts = host.split(':');
|
||||
let host = parts.next().unwrap();
|
||||
match parts
|
||||
.next()
|
||||
.map(|port_or_socket| u16::from_str(port_or_socket).map_err(|_| port_or_socket))
|
||||
{
|
||||
Some(Ok(port)) => (host, Some(port), None),
|
||||
Some(Err(socket)) => (host, None, Some(socket)),
|
||||
None => (host, None, None),
|
||||
let (host, port_or_socket) = host.rsplit_once(':').unwrap_or((host, ""));
|
||||
if port_or_socket.is_empty() {
|
||||
return (host, None, None);
|
||||
}
|
||||
match u16::from_str(port_or_socket) {
|
||||
Ok(port) => (host, Some(port), None),
|
||||
Err(_) => (host, None, Some(port_or_socket)),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -721,3 +721,35 @@ fn test_parse_postgres_escaped_credentials() {
|
|||
PgConnectOptions::from_str(&config.database.url()).unwrap(),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_ipv6_db() {
|
||||
let config = config_from_file("tests/configs/ipv6_db.php");
|
||||
assert_debug_equal(
|
||||
&Database::MySql {
|
||||
database: "nextcloud".to_string(),
|
||||
username: "nextcloud".to_string(),
|
||||
password: "secret".to_string(),
|
||||
connect: DbConnect::Tcp {
|
||||
host: "[::1]".to_string(),
|
||||
port: 123,
|
||||
},
|
||||
ssl_options: SslOptions::Default,
|
||||
},
|
||||
&config.database,
|
||||
);
|
||||
assert_eq!(
|
||||
config.database.url(),
|
||||
"mysql://nextcloud:secret@[::1]:123/nextcloud"
|
||||
);
|
||||
|
||||
assert_debug_equal(
|
||||
MySqlConnectOptions::new()
|
||||
.host("[::1]")
|
||||
.username("nextcloud")
|
||||
.password("secret")
|
||||
.port(123)
|
||||
.database("nextcloud"),
|
||||
MySqlConnectOptions::from_str(&config.database.url()).unwrap(),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
15
tests/configs/ipv6_db.php
Normal file
15
tests/configs/ipv6_db.php
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
$CONFIG = [
|
||||
'overwrite.cli.url' => 'https://cloud.example.com',
|
||||
'dbtype' => 'mysql',
|
||||
'dbname' => 'nextcloud',
|
||||
'dbhost' => '[::1]:123',
|
||||
'dbport' => '',
|
||||
'dbtableprefix' => 'oc_',
|
||||
'dbuser' => 'nextcloud',
|
||||
'dbpassword' => 'secret',
|
||||
'redis' => [
|
||||
'host' => 'localhost'
|
||||
]
|
||||
];
|
||||
Loading…
Add table
Add a link
Reference in a new issue