Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions crates/common/src/config/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{
path::{Path, PathBuf},
};

use eyre::{Context, Result, bail};
use eyre::{Context, Result};
use serde::de::DeserializeOwned;

use crate::{
Expand Down Expand Up @@ -60,11 +60,11 @@ pub fn decode_string_to_map(raw: &str) -> Result<HashMap<ModuleId, String>> {
raw.trim()
.split(',')
.map(|pair| {
let mut parts = pair.trim().split('=');
match (parts.next(), parts.next()) {
(Some(key), Some(value)) => Ok((ModuleId(key.into()), value.into())),
_ => bail!("Invalid key-value pair: {pair}"),
}
let (key, value) = pair
.trim()
.split_once('=')
.ok_or_else(|| eyre::eyre!("Invalid key-value pair: {pair}"))?;
Ok((ModuleId(key.into()), value.into()))
})
.collect()
}
Expand Down Expand Up @@ -120,6 +120,12 @@ mod tests {
assert_eq!(map.get(&ModuleId("ONLY".into())), Some(&"ONE".to_string()));
}

#[test]
fn test_decode_string_to_map_preserves_equals_in_value() {
let map = decode_string_to_map("MODULE=secret=with=equals").unwrap();
assert_eq!(map.get(&ModuleId("MODULE".into())), Some(&"secret=with=equals".to_string()));
}

#[test]
fn test_decode_string_to_map_empty_string() {
// An empty string yields one token with no `=`, which is invalid.
Expand Down