diff --git a/util/ocilayout/parse.go b/util/ocilayout/parse.go index 5c7dd8ed7..9e0b6ee42 100644 --- a/util/ocilayout/parse.go +++ b/util/ocilayout/parse.go @@ -1,7 +1,6 @@ package ocilayout import ( - "regexp" "strings" "github.com/distribution/reference" @@ -60,8 +59,13 @@ func (r Ref) String() string { return s } -var windowsDrivePath = regexp.MustCompile(`^[A-Za-z]:[\\/]`) - func isWindowsDrivePath(path string, colon int) bool { - return colon == 1 && windowsDrivePath.MatchString(path) + if colon != 1 || len(path) < 3 { + return false + } + if path[2] != '/' && path[2] != '\\' { + return false + } + c := path[0] + return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') } diff --git a/util/ocilayout/parse_test.go b/util/ocilayout/parse_test.go index 3b3e5e966..3a4fec0f2 100644 --- a/util/ocilayout/parse_test.go +++ b/util/ocilayout/parse_test.go @@ -72,12 +72,14 @@ func TestParse(t *testing.T) { dgst: "sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", }, } { - ref, ok, err := Parse(tt.s) - require.True(t, ok) - require.NoError(t, err) - assert.Equal(t, tt.path, ref.Path, "comparing path: %s", tt.s) - assert.Equal(t, tt.dgst, ref.Digest.String(), "comparing digest: %s", tt.s) - assert.Equal(t, tt.tag, ref.Tag, "comparing tag: %s", tt.s) + t.Run(tt.s, func(t *testing.T) { + ref, ok, err := Parse(tt.s) + require.True(t, ok) + require.NoError(t, err) + assert.Equal(t, tt.path, ref.Path, "comparing path: %s", tt.s) + assert.Equal(t, tt.dgst, ref.Digest.String(), "comparing digest: %s", tt.s) + assert.Equal(t, tt.tag, ref.Tag, "comparing tag: %s", tt.s) + }) } }