From 4489005cb2f11fe6e2dcdb181b4834791de3b73f Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Tue, 21 May 2013 12:53:05 +0000 Subject: [PATCH 1/2] add regexp check on repo's name --- commands.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/commands.go b/commands.go index 5e459a1d94..98e665cd40 100644 --- a/commands.go +++ b/commands.go @@ -17,6 +17,7 @@ import ( "os" "path/filepath" "reflect" + "regexp" "strconv" "strings" "text/tabwriter" @@ -641,6 +642,10 @@ func (cli *DockerCli) CmdPush(args ...string) error { if len(strings.SplitN(name, "/", 2)) == 1 { return fmt.Errorf("Impossible to push a \"root\" repository. Please rename your repository in / (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.Set("registry", *registry) From a55a0d370dfca169e0220a01c292c7d41ad0b557 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Mon, 3 Jun 2013 14:23:57 +0000 Subject: [PATCH 2/2] ([a-z0-9_]{4,30})/([a-zA-Z0-9-_.]+) --- commands.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/commands.go b/commands.go index 98e665cd40..1ab713ce5d 100644 --- a/commands.go +++ b/commands.go @@ -642,9 +642,14 @@ func (cli *DockerCli) CmdPush(args ...string) error { if len(strings.SplitN(name, "/", 2)) == 1 { return fmt.Errorf("Impossible to push a \"root\" repository. Please rename your repository in / (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") + nameParts := strings.SplitN(name, "/", 2) + validNamespace := regexp.MustCompile(`^([a-z0-9_]{4,30})$`) + if !validNamespace.MatchString(nameParts[0]) { + return fmt.Errorf("Invalid namespace name (%s), only [a-z0-9_] are allowed, size between 4 and 30", nameParts[0]) + } + validRepo := regexp.MustCompile(`^([a-zA-Z0-9-_.]+)$`) + if !validRepo.MatchString(nameParts[1]) { + return fmt.Errorf("Invalid repository name (%s), only [a-zA-Z0-9-_.] are allowed", nameParts[1]) } v := url.Values{}