1
0
Fork 0

Added a check for a website field's length.

This commit is contained in:
Alexander Andreev 2023-05-22 02:35:39 +04:00
parent 141e1215a3
commit 16e5ececf5
Signed by: Arav
GPG Key ID: D22A817D95815393
1 changed files with 9 additions and 0 deletions

View File

@ -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,