From 16e5ececf53e7a74655321229513cd2d609a07b9 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Mon, 22 May 2023 02:35:39 +0400 Subject: [PATCH] Added a check for a website field's length. --- guestbook.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/guestbook.go b/guestbook.go index 64db2c6..30a0197 100644 --- a/guestbook.go +++ b/guestbook.go @@ -2,6 +2,7 @@ package justguestbook import ( "errors" + "fmt" "time" ) @@ -9,6 +10,9 @@ const ( // DateFormat is a format of the date and time used in a guestbook. DateFormat = "2006-01-02 15:04:05" + // entryWebsiteMaxLength is a maximum length for a Website field of an Entry. + entryWebsiteMaxLength = 255 +) // Reply holds a reply for a guestbook's entry. type Reply struct { @@ -68,6 +72,11 @@ func NewEntry(name, message, website string, hideWebsite bool) (*Entry, error) { return nil, errors.New("name and message field are required") } + if len(website) > entryWebsiteMaxLength { + return nil, errors.New(fmt.Sprint("website field's max length is", + entryWebsiteMaxLength, "but", len(website), "was given")) + } + return &Entry{ Created: time.Now().UTC(), Name: name,