mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-12-05 02:11:10 +01:00
Improved color validation - now with fixes and a table driven test
This commit is contained in:
11
server.go
11
server.go
@@ -10,6 +10,7 @@ import (
|
||||
"math/big"
|
||||
"net"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
@@ -70,6 +71,10 @@ var (
|
||||
// ErrServerShuttingDown indicates that the server is in the process of
|
||||
// gracefully exiting.
|
||||
ErrServerShuttingDown = errors.New("server is shutting down")
|
||||
|
||||
// validColorRegexp is a regexp that lets you check if a particular
|
||||
// color string matches the standard hex color format #RRGGBB.
|
||||
validColorRegexp = regexp.MustCompile("^#[A-Fa-f0-9]{6}$")
|
||||
)
|
||||
|
||||
// server is the main server of the Lightning Network Daemon. The server houses
|
||||
@@ -2821,8 +2826,10 @@ func (s *server) Peers() []*peer {
|
||||
// form "#RRGGBB", parses the hex color values, and returns a color.RGBA
|
||||
// struct of the same color.
|
||||
func parseHexColor(colorStr string) (color.RGBA, error) {
|
||||
if len(colorStr) != 7 || colorStr[0] != '#' {
|
||||
return color.RGBA{}, errors.New("Color must be in format #RRGGBB")
|
||||
// Check if the hex color string is a valid color representation.
|
||||
if !validColorRegexp.MatchString(colorStr) {
|
||||
return color.RGBA{}, errors.New("Color must be specified " +
|
||||
"using a hexadecimal value in the form #RRGGBB")
|
||||
}
|
||||
|
||||
// Decode the hex color string to bytes.
|
||||
|
||||
Reference in New Issue
Block a user