Skip to content

Commit

Permalink
Fix an error handling when key contains any white space
Browse files Browse the repository at this point in the history
  • Loading branch information
moznion committed Jan 1, 2019
1 parent 54748e4 commit c08c1df
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions parser.go
Expand Up @@ -22,6 +22,9 @@ func Parse(tagString string) (map[string]string, error) {

if inKeyParsing {
if unicode.IsSpace(r) {
if len(key) > 0 {
return nil, errors.New("invalid custom tag syntax: key must not contain any white space, but it contains")
}
continue
}

Expand Down
6 changes: 6 additions & 0 deletions parser_test.go
Expand Up @@ -98,3 +98,9 @@ func TestShouldRaiseErrorWhenValueIsNotTerminated(t *testing.T) {
t.Fatal("expected error has not raised")
}
}

func TestShouldRaiseErrorWhenKeyContainsWhiteSpace(t *testing.T) {
if _, err := Parse(`foo:"bar" bu z:"qux"`); err == nil {
t.Fatal("expected error has not raised")
}
}

0 comments on commit c08c1df

Please sign in to comment.