...
This commit is contained in:
parent
9f2d8d2117
commit
c787b8b2dd
@ -11,7 +11,8 @@ type PartKind int
|
|||||||
|
|
||||||
// Levels of concreteness
|
// Levels of concreteness
|
||||||
const (
|
const (
|
||||||
Domain PartKind = iota
|
Invalid PartKind = iota
|
||||||
|
Domain
|
||||||
Namespace
|
Namespace
|
||||||
Name
|
Name
|
||||||
Tag
|
Tag
|
||||||
@ -140,11 +141,11 @@ func (r Ref) Less(o Ref) bool {
|
|||||||
// The length of the returned slice is always 5.
|
// The length of the returned slice is always 5.
|
||||||
func (r Ref) Parts() []string {
|
func (r Ref) Parts() []string {
|
||||||
return []string{
|
return []string{
|
||||||
Domain: r.domain,
|
r.domain,
|
||||||
Namespace: r.namespace,
|
r.namespace,
|
||||||
Name: r.name,
|
r.name,
|
||||||
Tag: r.tag,
|
r.tag,
|
||||||
Build: r.build,
|
r.build,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,6 +191,8 @@ func ParseRef(s string) Ref {
|
|||||||
r = r.WithTag(part)
|
r = r.WithTag(part)
|
||||||
case Build:
|
case Build:
|
||||||
r = r.WithBuild(part)
|
r = r.WithBuild(part)
|
||||||
|
case Invalid:
|
||||||
|
return Ref{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !r.Valid() {
|
if !r.Valid() {
|
||||||
@ -215,6 +218,9 @@ func Parts(s string) iter.Seq2[PartKind, string] {
|
|||||||
if len(s) > 255 || len(s) == 0 {
|
if len(s) > 255 || len(s) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if !isValidPart(string(s[0])) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
yieldValid := func(kind PartKind, value string) bool {
|
yieldValid := func(kind PartKind, value string) bool {
|
||||||
if !isValidPart(value) {
|
if !isValidPart(value) {
|
||||||
@ -259,6 +265,7 @@ func Parts(s string) iter.Seq2[PartKind, string] {
|
|||||||
}
|
}
|
||||||
state, j = Domain, i
|
state, j = Domain, i
|
||||||
default:
|
default:
|
||||||
|
yield(Invalid, "")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -269,7 +276,6 @@ 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])
|
||||||
|
2
x/build/blob/testdata/fuzz/FuzzParseRef/3e3b70dba384074d
vendored
Normal file
2
x/build/blob/testdata/fuzz/FuzzParseRef/3e3b70dba384074d
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
go test fuzz v1
|
||||||
|
string("0 /0")
|
Loading…
x
Reference in New Issue
Block a user