diff --git a/common/taler-common/src/config.rs b/common/taler-common/src/config.rs index 81a2d9f..590fa79 100644 --- a/common/taler-common/src/config.rs +++ b/common/taler-common/src/config.rs @@ -230,9 +230,19 @@ pub mod parser { } else { return Err(e); } - } else if let Some(secret_section) = + } else if let Some(mut secret_section) = secret_cfg.sections.swap_remove(§ion) { + // The secret file's lines point into the inner + // parser's list of files: renumber them into + // ours, which takes that list over. + let base = self.files.len(); + self.files.extend(secret_cfg.files); + for line in secret_section.values_mut() { + if let Some(loc) = &mut line.loc { + loc.file += base; + } + } self.sections .entry(section) .or_default() @@ -1179,6 +1189,31 @@ mod test { check_ok(); } + /// The diagnostics name the file a value of an `@inline-secret@` file + /// came from, and the files that file inlines in turn. + #[test] + fn inline_secret_diagnostics() { + let dir = tempfile::tempdir().unwrap(); + let main = dir.path().join("main.conf"); + let secret = dir.path().join("secret.conf"); + let extra = dir.path().join("extra.conf"); + std::fs::write(&main, "[a]\nX = 1\n@inline-secret@ s secret.conf\n").unwrap(); + std::fs::write(&secret, "[s]\nKEY = k\n@inline@ extra.conf\n").unwrap(); + std::fs::write(&extra, "\n\n\n[s]\nOTHER = o\n").unwrap(); + let cfg = Config::load(SOURCE, Some(&main)).unwrap(); + let mut out = Vec::new(); + cfg.print(&mut out, true).unwrap(); + let out = String::from_utf8(out).unwrap(); + for (path, line, value) in [ + (&main, 2, "X = 1"), + (&secret, 2, "KEY = k"), + (&extra, 5, "OTHER = o"), + ] { + let at = format!("# {}:{line}\n{value}\n", path.to_string_lossy()); + assert!(out.contains(&at), "{at:?} not in {out}"); + } + } + #[test] fn parsing() { let check = |err: &str, content: &str| check_err(err, Config::from_mem(content));