digest: better test coverage
Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
parent
6a74c94bf8
commit
ecb2ee3824
4 changed files with 116 additions and 11 deletions
|
@ -94,17 +94,10 @@ func FromString(s string) Digest {
|
|||
func (d Digest) Validate() error {
|
||||
s := string(d)
|
||||
|
||||
if !DigestRegexpAnchored.MatchString(s) {
|
||||
return ErrDigestInvalidFormat
|
||||
}
|
||||
|
||||
i := strings.Index(s, ":")
|
||||
if i < 0 {
|
||||
return ErrDigestInvalidFormat
|
||||
}
|
||||
|
||||
// case: "sha256:" with no hex.
|
||||
if i+1 == len(s) {
|
||||
// validate i then run through regexp
|
||||
if i < 0 || i+1 == len(s) || !DigestRegexpAnchored.MatchString(s) {
|
||||
return ErrDigestInvalidFormat
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue