From b05e702536c10f50ef34bfcbcee686b6f84ce8dc Mon Sep 17 00:00:00 2001 From: Arijit Basu Date: Wed, 26 Oct 2022 14:24:55 +0530 Subject: [PATCH] Actually validate the passed message --- src/cli.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 6063ab8..e4e4dd7 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,5 +1,6 @@ use crate::{app, yaml}; use anyhow::{bail, Context, Result}; +use app::ExternalMsg; use serde_json as json; use std::fs::File; use std::io::{BufRead, BufReader, Write}; @@ -216,10 +217,10 @@ fn fmt_msg_in(args: Vec) -> Result { // Since we'll mostly by passing json using `-m`, and json is faster than yaml // let's try to validate using json first. - let msg = if let Ok(val) = json::from_str::(&msg) { + let msg = if let Ok(val) = json::from_str::(&msg) { json::to_string(&val)? } else { - let val: yaml::Value = yaml::from_str(&msg)?; + let val: ExternalMsg = yaml::from_str(&msg)?; json::to_string(&val)? };