diff options
author | Aditya R <arajan@redhat.com> | 2022-04-22 13:46:37 +0530 |
---|---|---|
committer | Aditya R <arajan@redhat.com> | 2022-04-22 14:49:56 +0530 |
commit | f87f23e3b624e2831d501589c84767ff11419398 (patch) | |
tree | 7c2df7d42b5d0367580cbd1ed7de40e7ae6667c9 /pkg/specgenutil | |
parent | b46970763c3b1c75144c8d4acf8773f804035c8d (diff) | |
download | podman-f87f23e3b624e2831d501589c84767ff11419398.tar.gz podman-f87f23e3b624e2831d501589c84767ff11419398.tar.bz2 podman-f87f23e3b624e2831d501589c84767ff11419398.zip |
specgen-volumes: parse --mount using csv-reader instead of split by comma
Following commit ensures that csv escaping is supported while using
inline `--mount=type=......` flag with `podman run` by using
`encoding/csv` to parse options instead of performing a `split.String(`
by `comma`.
Closes: https://github.com/containers/podman/issues/13922
Signed-off-by: Aditya R <arajan@redhat.com>
Diffstat (limited to 'pkg/specgenutil')
-rw-r--r-- | pkg/specgenutil/volumes.go | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/pkg/specgenutil/volumes.go b/pkg/specgenutil/volumes.go index aa07de0af..95ce420f8 100644 --- a/pkg/specgenutil/volumes.go +++ b/pkg/specgenutil/volumes.go @@ -1,6 +1,7 @@ package specgenutil import ( + "encoding/csv" "fmt" "path/filepath" "strings" @@ -152,7 +153,15 @@ func findMountType(input string) (mountType string, tokens []string, err error) // Split by comma, iterate over the slice and look for // "type=$mountType". Everything else is appended to tokens. found := false - for _, s := range strings.Split(input, ",") { + csvReader := csv.NewReader(strings.NewReader(input)) + records, err := csvReader.ReadAll() + if err != nil { + return "", nil, err + } + if len(records) != 1 { + return "", nil, errInvalidSyntax + } + for _, s := range records[0] { kv := strings.Split(s, "=") if found || !(len(kv) == 2 && kv[0] == "type") { tokens = append(tokens, s) |