浏览代码

add regexp check on repo's name

Victor Vieux 12 年之前
父节点
当前提交
4489005cb2
共有 1 个文件被更改,包括 5 次插入0 次删除
  1. 5 0
      commands.go

+ 5 - 0
commands.go

@@ -17,6 +17,7 @@ import (
 	"os"
 	"os"
 	"path/filepath"
 	"path/filepath"
 	"reflect"
 	"reflect"
+	"regexp"
 	"strconv"
 	"strconv"
 	"strings"
 	"strings"
 	"text/tabwriter"
 	"text/tabwriter"
@@ -641,6 +642,10 @@ func (cli *DockerCli) CmdPush(args ...string) error {
 	if len(strings.SplitN(name, "/", 2)) == 1 {
 	if len(strings.SplitN(name, "/", 2)) == 1 {
 		return fmt.Errorf("Impossible to push a \"root\" repository. Please rename your repository in <user>/<repo> (ex: %s/%s)", out.Username, name)
 		return fmt.Errorf("Impossible to push a \"root\" repository. Please rename your repository in <user>/<repo> (ex: %s/%s)", out.Username, name)
 	}
 	}
+	validRepo := regexp.MustCompile(`^([a-z0-9]{4,30})/([a-z0-9-.]+)$`)
+	if !validRepo.MatchString(name) {
+		return fmt.Errorf("Invalid repository name, only alphanum, - and . are allowed")
+	}
 
 
 	v := url.Values{}
 	v := url.Values{}
 	v.Set("registry", *registry)
 	v.Set("registry", *registry)