From 968e403307a49f787a08b325b218b17a7034eb17 Mon Sep 17 00:00:00 2001 From: "D. Scott Boggs" Date: Thu, 27 Mar 2025 11:41:56 -0400 Subject: [PATCH] Fix problem with parsing output from different versions of dig --- src/dig_response.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/dig_response.rs b/src/dig_response.rs index 393013f..d4a36bd 100644 --- a/src/dig_response.rs +++ b/src/dig_response.rs @@ -73,14 +73,18 @@ impl DigResponse { ); if cmd.status.success() { Ok(serde_yaml_ng::from_str( - String::from_utf8(cmd.stdout.into_iter().skip(2).collect()) - // we skip two here --------------------------^ - // because the dig output starts with "-\n" which fails to parse. - .map_err(|error| { - error!(domain:?, error:?; "couldn't convert command output to a string"); - error - })? - .as_str(), + String::from_utf8(if cmd.stdout.starts_with(b"-\n") { + cmd.stdout.into_iter().skip(2).collect() + } else { + cmd.stdout + }) + // we skip two here --------------------------^ + // because the dig output starts with "-\n" which fails to parse. + .map_err(|error| { + error!(domain:?, error:?; "couldn't convert command output to a string"); + error + })? + .as_str(), )?) } else { error!(status:? = cmd.status,