Skip to content

Commit

Permalink
Merge pull request #275 from tellerops/fix-dotenv-quote
Browse files Browse the repository at this point in the history
Fix dotenv quote
  • Loading branch information
jondot authored May 15, 2024
2 parents 5064e4e + ad55573 commit 9186cfb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions teller-cli/fixtures/flow_test_vars.env
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
FOO="bar baz"
USER_NAME=linus
25 changes: 25 additions & 0 deletions teller-cli/tests/snapshots/flow_test__flow-test-dot-0.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 5 additions & 1 deletion teller-providers/src/providers/dotenv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ fn save(path: &Path, data: &BTreeMap<String, String>) -> Result<String> {
};

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)?;
Expand Down

0 comments on commit 9186cfb

Please sign in to comment.