From c631a9c72608720b70d5fbb67a0986a1ffa1f5a1 Mon Sep 17 00:00:00 2001 From: Blake Mizerany Date: Sat, 27 Apr 2024 17:58:41 -0700 Subject: [PATCH] types/model: relax name length constraint from 2 to 1 (#3984) --- types/model/name.go | 8 ++++---- types/model/name_test.go | 18 +++++++++++------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/types/model/name.go b/types/model/name.go index 591c331e..5497ec25 100644 --- a/types/model/name.go +++ b/types/model/name.go @@ -113,16 +113,16 @@ type Name struct { // length: [1, 350] // namespace: // pattern: alphanum { alphanum | "-" | "_" }* -// length: [2, 80] +// length: [1, 80] // model: // pattern: alphanum { alphanum | "-" | "_" | "." }* -// length: [2, 80] +// length: [1, 80] // tag: // pattern: alphanum { alphanum | "-" | "_" | "." }* // length: [1, 80] // digest: // pattern: alphanum { alphanum | "-" | ":" }* -// length: [2, 80] +// length: [1, 80] // // Most users should use [ParseName] instead, unless need to support // different defaults than DefaultName. @@ -254,7 +254,7 @@ func isValidLen(kind partKind, s string) bool { case kindTag: return len(s) >= 1 && len(s) <= 80 default: - return len(s) >= 2 && len(s) <= 80 + return len(s) >= 1 && len(s) <= 80 } } diff --git a/types/model/name_test.go b/types/model/name_test.go index 112df3eb..45d8457c 100644 --- a/types/model/name_test.go +++ b/types/model/name_test.go @@ -101,6 +101,11 @@ func TestParseNameParts(t *testing.T) { } var testCases = map[string]bool{ // name -> valid + "": false, + + // minimal + "h/n/m:t@d": true, + "host/namespace/model:tag": true, "host/namespace/model": false, "namespace/model": false, @@ -116,11 +121,12 @@ var testCases = map[string]bool{ // name -> valid "h/nn/mm:t@sha256-1000000000000000000000000000000000000000000000000000000000000000": true, // bare minimum part sizes "h/nn/mm:t@sha256:1000000000000000000000000000000000000000000000000000000000000000": true, // bare minimum part sizes - "m": false, // model too short - "n/mm:": false, // namespace too short - "h/n/mm:t": false, // namespace too short - "@t": false, // digest too short - "mm@d": false, // digest too short + // unqualified + "m": false, + "n/m:": false, + "h/n/m": false, + "@t": false, + "m@d": false, // invalids "^": false, @@ -140,8 +146,6 @@ var testCases = map[string]bool{ // name -> valid "hh/nn/mm:-tt@dd": false, "hh/nn/mm:tt@-dd": false, - "": false, - // hosts "host:https/namespace/model:tag": true,