From 487fb404bdb4dbf76473084acbd3e39929951de8 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 24 Jul 2021 19:02:42 +0100 Subject: [PATCH] config: dequote things Signed-off-by: Ian Jackson --- src/config.rs | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/src/config.rs b/src/config.rs index 18e4969..65877db 100644 --- a/src/config.rs +++ b/src/config.rs @@ -224,17 +224,32 @@ impl Aggregate { //dbg!( InstanceConfig::FIELDS );// check xxx vars are in fields let sn = sn.parse().dcontext(&sn)?; - self.sections.entry(sn) - .or_default() - .extend( - vars.into_iter() - .map(|(k,raw)| { - (k.replace('-',"_"), - RawVal { raw, loc: loc.clone() }) - }) - ); + let ent = self.sections.entry(sn).or_default(); + for (key, raw) in vars { + let raw = match raw { + Some(raw) if raw.starts_with('\'') || raw.starts_with('"') => Some( + (||{ + if raw.contains('\\') { + throw!( + anyhow!("quoted value contains backslash, not supported") + ); + } + let unq = raw[1..].strip_suffix(&raw[0..1]) + .ok_or_else( + || anyhow!("mismatched quotes around quoted value") + )? + .to_owned(); + Ok::<_,AE>(unq) + })() + .with_context(|| format!("key {:?}", key)) + .dcontext(path_for_loc)? + ), + x => x, + }; + let key = key.replace('-',"_"); + ent.insert(key, RawVal { raw, loc: loc.clone() }); + } } - } #[throws(AE)] // AE includes path -- 2.30.2