diff --git a/teller-cli/fixtures/flow_test_vars.env b/teller-cli/fixtures/flow_test_vars.env index 8a9b809a..3bd6f0d7 100644 --- a/teller-cli/fixtures/flow_test_vars.env +++ b/teller-cli/fixtures/flow_test_vars.env @@ -1 +1,2 @@ +FOO="bar baz" USER_NAME=linus diff --git a/teller-cli/tests/snapshots/flow_test__flow-test-dot-0.snap b/teller-cli/tests/snapshots/flow_test__flow-test-dot-0.snap index 25f1859a..07a05424 100644 --- a/teller-cli/tests/snapshots/flow_test__flow-test-dot-0.snap +++ b/teller-cli/tests/snapshots/flow_test__flow-test-dot-0.snap @@ -4,6 +4,31 @@ expression: res --- Ok( [ + KV { + value: "bar baz", + key: "FOO", + from_key: "FOO", + path: Some( + PathInfo { + id: "tvars", + path: "fixtures/flow_test_vars.env", + }, + ), + provider: Some( + ProviderInfo { + kind: Dotenv, + name: "dot_1", + }, + ), + meta: Some( + MetaInfo { + sensitivity: None, + redact_with: None, + source: None, + sink: None, + }, + ), + }, KV { value: "linus", key: "USER_NAME", diff --git a/teller-providers/src/providers/dotenv.rs b/teller-providers/src/providers/dotenv.rs index ac4fcbdc..eb7ef1f6 100644 --- a/teller-providers/src/providers/dotenv.rs +++ b/teller-providers/src/providers/dotenv.rs @@ -110,7 +110,11 @@ fn save(path: &Path, data: &BTreeMap) -> Result { }; let value = json_value.unwrap_or_else(|| v.to_string()); - out.push_str(&format!("{k}={value}\n")); + if value.chars().any(char::is_whitespace) && !value.starts_with(['"', '\'']) { + out.push_str(&format!("{k}=\"{value}\"\n")); + } else { + out.push_str(&format!("{k}={value}\n")); + } } fs::write(path, &out)?;