diff --git a/executor/oci/mounts.go b/executor/oci/mounts.go index 62dbd388..dddfb846 100644 --- a/executor/oci/mounts.go +++ b/executor/oci/mounts.go @@ -76,11 +76,11 @@ func withROBind(src, dest string) func(m []specs.Mount) ([]specs.Mount, error) { func hasPrefix(p, prefixDir string) bool { prefixDir = filepath.Clean(prefixDir) - if prefixDir == "/" { + if filepath.Base(prefixDir) == string(filepath.Separator) { return true } p = filepath.Clean(p) - return p == prefixDir || strings.HasPrefix(p, prefixDir+"/") + return p == prefixDir || strings.HasPrefix(p, prefixDir+string(filepath.Separator)) } func removeMountsWithPrefix(mounts []specs.Mount, prefixDir string) []specs.Mount { diff --git a/executor/oci/mounts_test.go b/executor/oci/mounts_test.go index dae76e1e..ec30a111 100644 --- a/executor/oci/mounts_test.go +++ b/executor/oci/mounts_test.go @@ -1,6 +1,7 @@ package oci import ( + "runtime" "testing" "github.com/stretchr/testify/assert" @@ -49,6 +50,45 @@ func TestHasPrefix(t *testing.T) { expected: false, }, } + if runtime.GOOS == "windows" { + testCases = append(testCases, + testCase{ + path: "C:\\foo\\bar", + prefix: "C:\\foo", + expected: true, + }, + testCase{ + path: "C:\\foo\\bar", + prefix: "C:\\foo\\", + expected: true, + }, + testCase{ + path: "C:\\foo\\bar", + prefix: "C:\\", + expected: true, + }, + testCase{ + path: "C:\\foo", + prefix: "C:\\foo", + expected: true, + }, + testCase{ + path: "C:\\foo\\bar", + prefix: "C:\\bar", + expected: false, + }, + testCase{ + path: "C:\\foo\\bar", + prefix: "foo", + expected: false, + }, + testCase{ + path: "C:\\foobar", + prefix: "C:\\foo", + expected: false, + }, + ) + } for i, tc := range testCases { actual := hasPrefix(tc.path, tc.prefix) assert.Equal(t, tc.expected, actual, "#%d: under(%q,%q)", i, tc.path, tc.prefix)