...
This commit is contained in:
parent
d42c3f6be1
commit
9f2d8d2117
@ -198,6 +198,11 @@ func ParseRef(s string) Ref {
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parts returns a sequence of the parts of a ref string from most specific
|
||||||
|
// to least specific.
|
||||||
|
//
|
||||||
|
// It normalizes the input string by removing "http://" and "https://" only.
|
||||||
|
// No other normalization is done.
|
||||||
func Parts(s string) iter.Seq2[PartKind, string] {
|
func Parts(s string) iter.Seq2[PartKind, string] {
|
||||||
return func(yield func(PartKind, string) bool) {
|
return func(yield func(PartKind, string) bool) {
|
||||||
if strings.HasPrefix(s, "http://") {
|
if strings.HasPrefix(s, "http://") {
|
||||||
@ -224,8 +229,7 @@ func Parts(s string) iter.Seq2[PartKind, string] {
|
|||||||
case '+':
|
case '+':
|
||||||
switch state {
|
switch state {
|
||||||
case Build:
|
case Build:
|
||||||
v := strings.ToUpper(s[i+1 : j])
|
if !yieldValid(Build, s[i+1:j]) {
|
||||||
if !yieldValid(Build, v) {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
state, j = Tag, i
|
state, j = Tag, i
|
||||||
@ -265,6 +269,7 @@ func Parts(s string) iter.Seq2[PartKind, string] {
|
|||||||
case Domain:
|
case Domain:
|
||||||
yieldValid(Domain, s[:j])
|
yieldValid(Domain, s[:j])
|
||||||
case Namespace:
|
case Namespace:
|
||||||
|
println("namespace", s[:j])
|
||||||
yieldValid(Namespace, s[:j])
|
yieldValid(Namespace, s[:j])
|
||||||
default:
|
default:
|
||||||
yieldValid(Name, s[:j])
|
yieldValid(Name, s[:j])
|
||||||
|
@ -24,9 +24,9 @@ var testRefs = map[string]Ref{
|
|||||||
// invalid
|
// invalid
|
||||||
"mistral:7b+Q4_0:latest": {},
|
"mistral:7b+Q4_0:latest": {},
|
||||||
"mi tral": {},
|
"mi tral": {},
|
||||||
|
"x/y/z/foo": {},
|
||||||
// From fuzzing
|
"/0": {},
|
||||||
"/0": {},
|
"0/": {},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRefParts(t *testing.T) {
|
func TestRefParts(t *testing.T) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user