fix(env): single-quote exported values in every product tree (#19)

`floci az env` printed the semicolon-separated Azure connection string
unquoted, so `eval $(floci az env)` set only
AZURE_STORAGE_CONNECTION_STRING=DefaultEndpointsProtocol=http and ran the
remaining segments as commands — `az` then reported "Invalid connection
string".

`floci env` and `floci gcp env` carried a byte-identical copy of the same
unquoted emitter (their values are `;`-free URLs today, so nobody hit it),
and the aws.cli.endpoint / az.cli.connection-string doctor checks suggested
export lines with the same flaw.

Extract the correct emitter that `floci oci env` already had into
io.floci.cli.output.ShellExport and use it everywhere: values are single
quoted with per-shell escaping for bash, fish, and PowerShell, so `;`, `$`,
backticks, and quotes can neither break nor inject through `eval`.

OciEnvFormatTest becomes ShellExportTest, keeping its four assertions and
adding the connection-string regression from the issue.

Closes #18
This commit is contained in:
Hector Ventura authored and GitHub committed 2026-08-26 22:12:29 -05:00
1 parent fee32a76a1
commit 6496795708
11 files changed
+99 -91

No files matched your search

@@ -6,6 +6,7 @@ import io.floci.cli.docker.DockerClient;
import io.floci.cli.output.Ansi;
import io.floci.cli.output.OutputFormat;
import io.floci.cli.output.Printer;
import io.floci.cli.output.ShellExport;
import picocli.CommandLine.*;
import java.net.URI;
@@ -63,7 +64,7 @@ public class GcpEnvCommand implements Callable<Integer> {
}
for (Map.Entry<String, String> entry : vars.entrySet()) {
printer.println(formatExport(entry.getKey(), entry.getValue()));
printer.println(ShellExport.formatExport(shell, entry.getKey(), entry.getValue()));
}
printer.println("");
printer.println(Ansi.gray("# Run: eval $(floci gcp env)"));
@@ -103,14 +104,6 @@ public class GcpEnvCommand implements Callable<Integer> {
return hostPort;
}
private String formatExport(String key, String value) {
return switch (shell.toLowerCase()) {
case "fish" -> "set -x " + key + " \"" + value + "\"";
case "powershell", "ps1" -> "$env:" + key + " = \"" + value + "\"";
default -> "export " + key + "=" + value;
};
}
private String extractHost(String endpoint) {
try {
String h = URI.create(endpoint).getHost();