Skip to content

Commit

Permalink
Merge pull request #13969 from flouthoc/mount-csv-parsing
Browse files Browse the repository at this point in the history
specgen-volumes: parse `--mount` using csv-reader instead of split.
  • Loading branch information
openshift-merge-robot authored Apr 22, 2022
2 parents 0d6af14 + f87f23e commit 04acbaa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/specgenutil/volumes.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package specgenutil

import (
"encoding/csv"
"fmt"
"path/filepath"
"strings"
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions test/e2e/run_volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ var _ = Describe("Podman run with volumes", func() {
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())

// test csv escaping
session = podmanTest.Podman([]string{"run", "--rm", "--mount=type=tmpfs,tmpfs-size=512M,\"destination=/test,\"", ALPINE, "ls", "/test,"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))

session = podmanTest.Podman([]string{"run", "--rm", "--mount", "type=bind,src=/tmp,target=/tmp,tmpcopyup", ALPINE, "true"})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
Expand Down

0 comments on commit 04acbaa

Please sign in to comment.