Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions util/ocilayout/parse.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ocilayout

import (
"regexp"
"strings"

"github.com/distribution/reference"
Expand Down Expand Up @@ -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')
}
14 changes: 8 additions & 6 deletions util/ocilayout/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
}

Expand Down
Loading