diff --git a/build/blob/ref.go b/build/blob/ref.go index 093701e1..e7c75841 100644 --- a/build/blob/ref.go +++ b/build/blob/ref.go @@ -204,6 +204,9 @@ func ParseRef(s string) Ref { switch state { case build: r.build = s[i+1 : j] + if r.build == "" { + return Ref{} + } r.build = strings.ToUpper(r.build) state, j = tag, i default: @@ -213,6 +216,9 @@ func ParseRef(s string) Ref { switch state { case build, tag: r.tag = s[i+1 : j] + if r.tag == "" { + return Ref{} + } state, j = name, i default: return Ref{} diff --git a/build/blob/ref_test.go b/build/blob/ref_test.go index 03f6ca24..bf4333df 100644 --- a/build/blob/ref_test.go +++ b/build/blob/ref_test.go @@ -16,7 +16,7 @@ var testRefs = map[string]Ref{ "mistral+KQED": {name: "mistral", build: "KQED"}, "mistral.x-3:7b+Q4_0": {name: "mistral.x-3", tag: "7b", build: "Q4_0"}, "mistral:7b+q4_0": {name: "mistral", tag: "7b", build: "Q4_0"}, - "llama2:+": {name: "llama2"}, + "llama2": {name: "llama2"}, // invalid "mistral:7b+Q4_0:latest": {}, @@ -38,6 +38,11 @@ func TestParseRef(t *testing.T) { if got != want { t.Errorf("ParseRef(%q) = %q; want %q", s, got, want) } + + // test round-trip + if ParseRef(got.String()) != got { + t.Errorf("String() = %q; want %q", got.String(), s) + } }) } } @@ -56,6 +61,7 @@ func TestRefFull(t *testing.T) { {"example.com/x/mistral:latest+Q4_0", "example.com/x/mistral:latest+Q4_0"}, {"mistral:7b+x", "!(MISSING DOMAIN)/!(MISSING NAMESPACE)/mistral:7b+X"}, + {"mistral:7b+q4_0", "!(MISSING DOMAIN)/!(MISSING NAMESPACE)/mistral:7b+Q4_0"}, {"mistral:7b+Q4_0", "!(MISSING DOMAIN)/!(MISSING NAMESPACE)/mistral:7b+Q4_0"}, {"mistral:latest", "!(MISSING DOMAIN)/!(MISSING NAMESPACE)/mistral:latest+!(MISSING BUILD)"}, {"mistral", "!(MISSING DOMAIN)/!(MISSING NAMESPACE)/mistral:!(MISSING TAG)+!(MISSING BUILD)"},