handle redis db index as str

This commit is contained in:
Robin Appelman 2025-08-11 10:46:04 +02:00
commit 484af6a8e7
5 changed files with 31 additions and 3 deletions

2
Cargo.lock generated
View file

@ -836,7 +836,7 @@ dependencies = [
[[package]] [[package]]
name = "nextcloud-config-parser" name = "nextcloud-config-parser"
version = "0.14.0" version = "0.14.1"
dependencies = [ dependencies = [
"form_urlencoded", "form_urlencoded",
"itertools", "itertools",

View file

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

View file

@ -331,7 +331,11 @@ fn parse_redis_options(parsed: &Value, key: &str) -> RedisConfig {
None None
}; };
let db = redis_options["dbindex"].clone().into_int().unwrap_or(0); let db = redis_options["dbindex"].clone().into_int().or_else(|| {
redis_options["dbindex"]
.as_str()
.and_then(|i| i64::from_str(i).ok())
}).unwrap_or(0);
let password = redis_options["password"] let password = redis_options["password"]
.as_str() .as_str()
.filter(|pass| !pass.is_empty()) .filter(|pass| !pass.is_empty())

View file

@ -108,6 +108,15 @@ fn test_parse_redis_socket() {
); );
} }
#[test]
fn test_parse_redis_db_str() {
let config = config_from_file("tests/configs/redis_db_str.php");
assert_debug_equal(
RedisConfig::Single(parse_redis("redis://127.0.0.1/1")),
config.redis,
);
}
#[test] #[test]
fn test_parse_notify_push_redis() { fn test_parse_notify_push_redis() {
let config = config_from_file("tests/configs/notify_push_redis.php"); let config = config_from_file("tests/configs/notify_push_redis.php");

View file

@ -0,0 +1,15 @@
<?php
$CONFIG = [
'overwrite.cli.url' => 'https://cloud.example.com',
'dbtype' => 'mysql',
'dbname' => 'nextcloud',
'dbhost' => 'localhost',
'dbport' => '',
'dbuser' => 'nextcloud',
'dbpassword' => 'secret',
'redis' => [
'host' => 'localhost',
'dbindex' => '1',
]
];