Clarify requirements for identifiers validation
Fix commentary to be clear that the RFC1035 2.3.1 rules are not explicitly enforced by the identifiers regex. Add a test to show the lessened restrictions for digits to follow hyphen and period. Signed-off-by: Phil Estes <estesp@linux.vnet.ibm.com>
This commit is contained in:
parent
76aa4e546e
commit
fdf7a795bc
@ -42,13 +42,13 @@ var (
|
|||||||
identifierRe = regexp.MustCompile(reAnchor(alphanum + reGroup(separators+reGroup(alphanum)) + "*"))
|
identifierRe = regexp.MustCompile(reAnchor(alphanum + reGroup(separators+reGroup(alphanum)) + "*"))
|
||||||
)
|
)
|
||||||
|
|
||||||
// Validate return nil if the string s is a valid identifier.
|
// Validate returns nil if the string s is a valid identifier.
|
||||||
//
|
//
|
||||||
// identifiers must be valid domain names according to RFC 1035, section 2.3.1. To
|
// identifiers are similar to the domain name rules according to RFC 1035, section 2.3.1. However
|
||||||
// enforce case insensitivity, all characters must be lower case.
|
// rules in this package are relaxed to allow numerals to follow period (".") and mixed case is
|
||||||
|
// allowed.
|
||||||
//
|
//
|
||||||
// In general, identifiers that pass this validation, should be safe for use as
|
// In general identifiers that pass this validation should be safe for use as filesystem path components.
|
||||||
// a domain names or filesystem path component.
|
|
||||||
func Validate(s string) error {
|
func Validate(s string) error {
|
||||||
if len(s) == 0 {
|
if len(s) == 0 {
|
||||||
return errors.Wrapf(errdefs.ErrInvalidArgument, "identifier must not be empty")
|
return errors.Wrapf(errdefs.ErrInvalidArgument, "identifier must not be empty")
|
||||||
|
@ -34,6 +34,7 @@ func TestValidIdentifiers(t *testing.T) {
|
|||||||
"swarmkit.docker.io",
|
"swarmkit.docker.io",
|
||||||
"0912341234",
|
"0912341234",
|
||||||
"task.0.0123456789",
|
"task.0.0123456789",
|
||||||
|
"container.system-75-f19a.00",
|
||||||
"underscores_are_allowed",
|
"underscores_are_allowed",
|
||||||
strings.Repeat("a", maxLength),
|
strings.Repeat("a", maxLength),
|
||||||
} {
|
} {
|
||||||
|
Loading…
Reference in New Issue
Block a user