From 40aea0c70db7e019a26589e86594ab737e58e286 Mon Sep 17 00:00:00 2001 From: Solly Ross Date: Thu, 1 Aug 2019 17:15:39 -0700 Subject: [PATCH] Validation: len is measured in bytes The `TooLong` validation message mentioned characters, but the `len` function actually measures bytes, no characters. This switches it over to use bytes. Characters are mostly an illusory concept anyway -- a vain attempt to shield our minds against the lovecraftian nightmares that comes from attemping to truly comprehend that eldritch treatise known as the Unicode standard. Which is to say: measuring things in characters is hard and mostly ambiguous, and probably not what we meant to do. --- .../src/k8s.io/apimachinery/pkg/util/validation/field/errors.go | 2 +- test/integration/master/synthetic_master_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/staging/src/k8s.io/apimachinery/pkg/util/validation/field/errors.go b/staging/src/k8s.io/apimachinery/pkg/util/validation/field/errors.go index 1d372a5259c..0cd5d65775a 100644 --- a/staging/src/k8s.io/apimachinery/pkg/util/validation/field/errors.go +++ b/staging/src/k8s.io/apimachinery/pkg/util/validation/field/errors.go @@ -204,7 +204,7 @@ func Forbidden(field *Path, detail string) *Error { // Invalid, but the returned error will not include the too-long // value. func TooLong(field *Path, value interface{}, maxLength int) *Error { - return &Error{ErrorTypeTooLong, field.String(), value, fmt.Sprintf("must have at most %d characters", maxLength)} + return &Error{ErrorTypeTooLong, field.String(), value, fmt.Sprintf("must have at most %d bytes", maxLength)} } // TooMany returns a *Error indicating "too many". This is used to diff --git a/test/integration/master/synthetic_master_test.go b/test/integration/master/synthetic_master_test.go index 804296c07d6..ec89466fdcd 100644 --- a/test/integration/master/synthetic_master_test.go +++ b/test/integration/master/synthetic_master_test.go @@ -313,7 +313,7 @@ func TestObjectSizeResponses(t *testing.T) { expectedMsgFor1MB := `etcdserver: request is too large` expectedMsgFor2MB := `rpc error: code = ResourceExhausted desc = trying to send message larger than max` expectedMsgFor3MB := `Request entity too large: limit is 3145728` - expectedMsgForLargeAnnotation := `metadata.annotations: Too long: must have at most 262144 characters` + expectedMsgForLargeAnnotation := `metadata.annotations: Too long: must have at most 262144 bytes` deployment1 := constructBody("a", DeploymentMegabyteSize, "labels", t) // >1 MB file deployment2 := constructBody("a", DeploymentTwoMegabyteSize, "labels", t) // >2 MB file