浏览代码

Make volumes opts more strict

Guillaume J. Charmes 11 年之前
父节点
当前提交
c7661f40b6
共有 1 个文件被更改,包括 6 次插入2 次删除
  1. 6 2
      commands.go

+ 6 - 2
commands.go

@@ -1666,8 +1666,11 @@ func (opts PathOpts) String() string { return fmt.Sprintf("%v", map[string]struc
 func (opts PathOpts) Set(val string) error {
 	var containerPath string
 
-	splited := strings.SplitN(val, ":", 2)
-	if len(splited) == 1 {
+	if strings.Count(val, ":") > 2 {
+		return fmt.Errorf("bad format for volumes: %s", val)
+	}
+
+	if splited := strings.SplitN(val, ":", 2); len(splited) == 1 {
 		containerPath = splited[0]
 		val = filepath.Clean(splited[0])
 	} else {
@@ -1680,6 +1683,7 @@ func (opts PathOpts) Set(val string) error {
 		return fmt.Errorf("%s is not an absolute path", containerPath)
 	}
 	opts[val] = struct{}{}
+
 	return nil
 }