feat(export): support dotenv quote styles#251
Conversation
|
| Filename | Overview |
|---|---|
| packages/cmd/export.go | Adds --quote flag (single/double/none) for dotenv/dotenv-export formats. Single-quote style doesn't escape embedded ' characters, producing malformed output for affected values; double-quote escaping is correct. |
| packages/cmd/export_test.go | Adds tests for all three quote styles and an invalid-style rejection case; no test exercises a value containing a literal single-quote character, which is the gap that would catch the escaping bug. |
Reviews (1): Last reviewed commit: "feat(export): support dotenv quote style..." | Re-trigger Greptile
| case DotEnvQuoteStyleSingle: | ||
| return fmt.Sprintf("'%s'", value), nil |
There was a problem hiding this comment.
The
single quote style wraps values in '...' but never escapes embedded single-quote characters. A secret value like it's a private key produces KEY='it's a private key' — a broken dotenv line. The double style correctly escapes " with \", so the same care is needed here. In POSIX-style dotenv parsers, single quotes don't support escape sequences, so the only safe workaround is to use '\'' (end quote, literal ', reopen quote), or to detect and error when the value contains ' under this style.
| case DotEnvQuoteStyleSingle: | |
| return fmt.Sprintf("'%s'", value), nil | |
| case DotEnvQuoteStyleSingle: | |
| if strings.ContainsRune(value, '\'') { | |
| return "", fmt.Errorf("single quote style cannot be used for values that contain a single quote character; use --quote=double instead") | |
| } | |
| return fmt.Sprintf("'%s'", value), nil |
| exportCmd.Flags().StringP("env", "e", "dev", "Set the environment (dev, prod, etc.) from which your secrets should be pulled from") | ||
| exportCmd.Flags().Bool("expand", true, "Parse shell parameter expansions in your secrets") | ||
| exportCmd.Flags().StringP("format", "f", "dotenv", "Set the format of the output file (dotenv, json, csv)") | ||
| exportCmd.Flags().String("quote", DotEnvQuoteStyleSingle, "Set the quote style for dotenv output (single, double, none)") |
There was a problem hiding this comment.
The
--quote flag is read and validated regardless of the chosen --format, but it is silently ignored when the format is json, csv, or yaml. A user who runs infisical export --format=json --quote=double will get no warning that the flag had no effect. Consider emitting a message to stderr (or returning an error) when --quote is set to a non-default value alongside a format that doesn't use it.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Context
Adds a
--quoteoption toinfisical exportfor dotenv and dotenv-export output so users can choosesingle,double, ornonequote styles while preserving the current single-quote default. This addresses multiline/private-key workflows from Infisical/infisical#1103 without changing JSON, CSV, or YAML output.Screenshots
Not applicable.
Steps to verify the change
Type
Checklist