We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 5982a7a + 399513b commit b68404aCopy full SHA for b68404a
imagex/colorx/colorx.go
@@ -14,7 +14,7 @@ var errInvalidFormat = errors.New("invalid format")
14
func ParseHexColor(s string) (c color.RGBA, err error) {
15
c.A = 0xff
16
17
- if s[0] != '#' {
+ if len(s) == 0 || s[0] != '#' {
18
return c, errInvalidFormat
19
}
20
imagex/colorx/colorx_test.go
@@ -2,6 +2,7 @@ package colorx
2
3
import (
4
"fmt"
5
+ "testing"
6
)
7
8
// ExampleParseHexColor shows how to use the ParseHexColor() function.
@@ -31,3 +32,10 @@ func ExampleParseHexColor() {
31
32
// #abcd = { 0 0 0 255}, invalid format
33
// #-12 = { 0 17 34 255}, invalid format
34
35
+
36
+func TestParseHexColor(t *testing.T) {
37
+ _, err := ParseHexColor("")
38
+ if err == nil {
39
+ t.Errorf("empty string should return error")
40
+ }
41
+}
0 commit comments