diff --git a/x/build/blob/ref.go b/x/build/blob/ref.go index 116c5896..72b1bf8b 100644 --- a/x/build/blob/ref.go +++ b/x/build/blob/ref.go @@ -7,6 +7,8 @@ import ( "strings" ) +const MaxRefLength = 255 + type PartKind int // Levels of concreteness @@ -224,7 +226,7 @@ func Parts(s string) iter.Seq2[PartKind, string] { s = s[len("https://"):] } - if len(s) > 255 || len(s) == 0 { + if len(s) > MaxRefLength || len(s) == 0 { return } diff --git a/x/build/blob/ref_test.go b/x/build/blob/ref_test.go index 5e931878..570e91bf 100644 --- a/x/build/blob/ref_test.go +++ b/x/build/blob/ref_test.go @@ -5,11 +5,6 @@ import ( "testing" ) -// test refs -const ( - refTooLong = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" -) - var testRefs = map[string]Ref{ "mistral:latest": {name: "mistral", tag: "latest"}, "mistral": {name: "mistral"}, @@ -38,6 +33,9 @@ var testRefs = map[string]Ref{ "file:///etc/passwd": {}, "file:///etc/passwd:latest": {}, "file:///etc/passwd:latest+u": {}, + + strings.Repeat("a", MaxRefLength): {name: strings.Repeat("a", MaxRefLength)}, + strings.Repeat("a", MaxRefLength+1): {}, } func TestRefParts(t *testing.T) { @@ -48,7 +46,7 @@ func TestRefParts(t *testing.T) { } } -func TestParseRefWithAndWithoutPrefixes(t *testing.T) { +func TestParseRef(t *testing.T) { for s, want := range testRefs { for _, prefix := range []string{"", "https://", "http://"} { // We should get the same results with or without the @@ -104,9 +102,11 @@ func TestRefFull(t *testing.T) { func TestParseRefAllocs(t *testing.T) { // test allocations + var r Ref allocs := testing.AllocsPerRun(1000, func() { - ParseRef("example.com/mistral:7b+Q4_0") + r = ParseRef("example.com/mistral:7b+Q4_0") }) + _ = r if allocs > 0 { t.Errorf("ParseRef allocs = %v; want 0", allocs) }