From 36c413577b582219401905af7d33d54e29eb4b68 Mon Sep 17 00:00:00 2001 From: Marcello Lamonaca Date: Sat, 10 Jun 2023 18:34:26 +0200 Subject: [PATCH] fix: escape double quotes (") in strings --- src/main.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 7cbe5d9..8d571a2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -110,11 +110,12 @@ impl EnvVar { impl Display for EnvVar { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let key = self.name.clone(); match self.value.clone() { - Value::Null => write!(f, "{key}=null", key = self.name), - Value::Bool(bool) => write!(f, "{key}={bool}", key = self.name), - Value::Number(number) => write!(f, "{key}={number}", key = self.name), - Value::String(string) => write!(f, "{key}=\"{string}\"", key = self.name), + Value::Null => write!(f, "{key}=null"), + Value::Bool(bool) => write!(f, "{key}={bool}",), + Value::Number(number) => write!(f, "{key}={number}"), + Value::String(string) => write!(f, r#"{key}="{}""#, string.replace('"', r#"\""#)), _ => Err(std::fmt::Error), } }