diff --git a/util/ocilayout/parse.go b/util/ocilayout/parse.go index 2b716d48f..5c7dd8ed7 100644 --- a/util/ocilayout/parse.go +++ b/util/ocilayout/parse.go @@ -1,6 +1,7 @@ package ocilayout import ( + "regexp" "strings" "github.com/distribution/reference" @@ -59,10 +60,8 @@ func (r Ref) String() string { return s } +var windowsDrivePath = regexp.MustCompile(`^[A-Za-z]:[\\/]`) + func isWindowsDrivePath(path string, colon int) bool { - if colon != 1 || len(path) < 2 { - return false - } - c := path[0] - return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') + return colon == 1 && windowsDrivePath.MatchString(path) } diff --git a/util/ocilayout/parse_test.go b/util/ocilayout/parse_test.go index d2ecf5153..3b3e5e966 100644 --- a/util/ocilayout/parse_test.go +++ b/util/ocilayout/parse_test.go @@ -40,11 +40,21 @@ func TestParse(t *testing.T) { path: "/path/to/oci/@/layout", tag: "latest", }, + { + s: "oci-layout://a:1.3", + path: "a", + tag: "1.3", + }, { s: `oci-layout://C:\path\to\oci\layout`, path: `C:\path\to\oci\layout`, tag: "latest", }, + { + s: `oci-layout://C:/path/to/oci/layout`, + path: `C:/path/to/oci/layout`, + tag: "latest", + }, { s: `oci-layout://C:\path\to\oci\layout:1.3`, path: `C:\path\to\oci\layout`,