diff --git a/types/operator_metadata_test.go b/types/operator_metadata_test.go index eb7e8059..c08cfcc8 100644 --- a/types/operator_metadata_test.go +++ b/types/operator_metadata_test.go @@ -18,7 +18,7 @@ func TestOperatorMetadata(t *testing.T) { name: "Valid metadata with twitter.com url", metadata: OperatorMetadata{ Name: "Ethereum Utopia", - Description: "Madhur's first operator is best in this world+&~#$—%’", + Description: "Madhur's first operator is best in this world+&~#$—%’“”", Logo: "https://goerli-operator-metadata.s3.amazonaws.com/eigenlayer.png", Twitter: "https://twitter.com/test", Website: "https://test.com", @@ -100,7 +100,7 @@ func TestOperatorMetadata(t *testing.T) { expectedError: utils.ErrInvalidImageMimeType, }, { - name: "Invalid metadata - name > 200 characters", + name: "Invalid metadata - name > 500 characters", metadata: OperatorMetadata{ Name: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.", Description: "test", @@ -108,10 +108,10 @@ func TestOperatorMetadata(t *testing.T) { Twitter: "https://twitter.com/test", Website: "https://test.com", }, - expectedError: utils.WrapError(ErrInvalidName, utils.ErrTextTooLong), + expectedError: utils.WrapError(ErrInvalidName, utils.ErrTextTooLong(utils.TextCharsLimit)), }, { - name: "Invalid metadata - description > 200 characters", + name: "Invalid metadata - description > 500 characters", metadata: OperatorMetadata{ Name: "test", Description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.", @@ -119,7 +119,7 @@ func TestOperatorMetadata(t *testing.T) { Twitter: "https://twitter.com/test", Website: "https://test.com", }, - expectedError: utils.WrapError(ErrInvalidDescription, utils.ErrTextTooLong), + expectedError: utils.WrapError(ErrInvalidDescription, utils.ErrTextTooLong(utils.TextCharsLimit)), }, { name: "Invalid metadata - no logo", diff --git a/utils/errors.go b/utils/errors.go index 349cdd13..02a1d9ac 100644 --- a/utils/errors.go +++ b/utils/errors.go @@ -7,10 +7,12 @@ import ( ) var ( - ErrInvalidUrl = errors.New("invalid url") - ErrInvalidGithubRawUrl = errors.New("invalid github raw url") - ErrInvalidText = fmt.Errorf("invalid text format, doesn't conform to regex %s", TextRegex) - ErrTextTooLong = errors.New("text should be less than 500 characters") + ErrInvalidUrl = errors.New("invalid url") + ErrInvalidGithubRawUrl = errors.New("invalid github raw url") + ErrInvalidText = fmt.Errorf("invalid text format, doesn't conform to regex %s", TextRegex) + ErrTextTooLong = func(limit int) error { + return fmt.Errorf("text should be less than %d characters", limit) + } ErrEmptyText = errors.New("text is empty") ErrInvalidImageExtension = errors.New( "invalid image extension. only " + strings.Join(ImageExtensions, ",") + " is supported", diff --git a/utils/utils.go b/utils/utils.go index 6013eb8c..8fe8471a 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -26,10 +26,12 @@ import ( const ( PngMimeType = "image/png" - TextRegex = `^[a-zA-Z0-9 +.,;:?!'’"\-_/()\[\]~&#$—%]+$` + TextRegex = `^[a-zA-Z0-9 +.,;:?!'’"“”\-_/()\[\]~&#$—%]+$` // Limit Http response to 1 MB httpResponseLimitBytes = 1 * 1024 * 1024 + + TextCharsLimit = 500 ) var ( @@ -240,8 +242,8 @@ func ValidateText(text string) error { return ErrEmptyText } - if len(text) > 500 { - return ErrTextTooLong + if len(text) > TextCharsLimit { + return ErrTextTooLong(TextCharsLimit) } // Regular expression to validate text