tools::config: error on newlines in string values

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2022-01-05 10:03:44 +01:00
parent c772a4a683
commit ba857cbe68

View File

@ -137,7 +137,12 @@ fn object_to_writer(output: &mut dyn Write, object: &Object) -> Result<(), Error
match value {
Value::Null => continue, // delete this entry
Value::Bool(v) => writeln!(output, "{}: {}", key, v)?,
Value::String(v) => writeln!(output, "{}: {}", key, v)?,
Value::String(v) => {
if v.as_bytes().contains(&b'\n') {
bail!("value for {} contains newlines", key);
}
writeln!(output, "{}: {}", key, v)?
}
Value::Number(v) => writeln!(output, "{}: {}", key, v)?,
Value::Array(_) => bail!("arrays are not supported in config files"),
Value::Object(_) => bail!("complex objects are not supported in config files"),