Skip to content

Commit

Permalink
add charcaters to regex
Browse files Browse the repository at this point in the history
  • Loading branch information
shrimalmadhur committed Jul 30, 2024
1 parent c178d0e commit 166f9d9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
6 changes: 3 additions & 3 deletions types/operator_metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -100,15 +100,15 @@ 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",
Logo: "https://goerli-operator-metadata.s3.amazonaws.com/eigenlayer.png",
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",
Expand Down
10 changes: 6 additions & 4 deletions utils/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 5 additions & 3 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 166f9d9

Please sign in to comment.