Added a check for a website field's length.
This commit is contained in:
parent
141e1215a3
commit
16e5ececf5
@ -2,6 +2,7 @@ package justguestbook
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -9,6 +10,9 @@ const (
|
|||||||
// DateFormat is a format of the date and time used in a guestbook.
|
// DateFormat is a format of the date and time used in a guestbook.
|
||||||
DateFormat = "2006-01-02 15:04:05"
|
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.
|
// Reply holds a reply for a guestbook's entry.
|
||||||
type Reply struct {
|
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")
|
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{
|
return &Entry{
|
||||||
Created: time.Now().UTC(),
|
Created: time.Now().UTC(),
|
||||||
Name: name,
|
Name: name,
|
||||||
|
Loading…
Reference in New Issue
Block a user