Skip to content

Commit c08c1df

Browse files
committed
Fix an error handling when key contains any white space
1 parent 54748e4 commit c08c1df

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

parser.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ func Parse(tagString string) (map[string]string, error) {
2222

2323
if inKeyParsing {
2424
if unicode.IsSpace(r) {
25+
if len(key) > 0 {
26+
return nil, errors.New("invalid custom tag syntax: key must not contain any white space, but it contains")
27+
}
2528
continue
2629
}
2730

parser_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,9 @@ func TestShouldRaiseErrorWhenValueIsNotTerminated(t *testing.T) {
9898
t.Fatal("expected error has not raised")
9999
}
100100
}
101+
102+
func TestShouldRaiseErrorWhenKeyContainsWhiteSpace(t *testing.T) {
103+
if _, err := Parse(`foo:"bar" bu z:"qux"`); err == nil {
104+
t.Fatal("expected error has not raised")
105+
}
106+
}

0 commit comments

Comments
 (0)