Blake Mizerany 1 год назад
Родитель
Сommit
2751c26da7
2 измененных файлов с 10 добавлено и 8 удалено
  1. 3 1
      x/build/blob/ref.go
  2. 7 7
      x/build/blob/ref_test.go

+ 3 - 1
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
 		}
 

+ 7 - 7
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)
 	}