cmd/vet: check only for ASCII spaces (0x20) in struct tags

Change-Id: I6e9b5caeca842b6bf72afefb31f5140608b86d20
Reviewed-on: https://go-review.googlesource.com/58530
Run-TryBot: Francesc Campoy Flores <campoy@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarRob Pike <r@golang.org>
parent 6d7db25e
...@@ -13,7 +13,6 @@ import ( ...@@ -13,7 +13,6 @@ import (
"reflect" "reflect"
"strconv" "strconv"
"strings" "strings"
"unicode"
) )
func init() { func init() {
...@@ -195,7 +194,7 @@ func validateStructTag(tag string) error { ...@@ -195,7 +194,7 @@ func validateStructTag(tag string) error {
value = value[comma+1:] value = value[comma+1:]
} }
if strings.IndexFunc(value, unicode.IsSpace) >= 0 { if strings.IndexByte(value, ' ') >= 0 {
return errTagValueSpace return errTagValueSpace
} }
} }
......
...@@ -83,15 +83,14 @@ type DuplicateJSONFields struct { ...@@ -83,15 +83,14 @@ type DuplicateJSONFields struct {
type UnexpectedSpacetest struct { type UnexpectedSpacetest struct {
A int `json:"a,omitempty"` A int `json:"a,omitempty"`
B int `json:"b, omitempty"` // ERROR "suspicious space found in struct tag value" B int `json:"b, omitempty"` // ERROR "suspicious space found in struct tag value"
C int `json:"c,omitempty\t"` // ERROR "suspicious space found in struct tag value" C int `json:"d ,omitempty"`
D int `json:"d ,omitempty"` D int `json:"e,omitempty, string"` // ERROR "suspicious space found in struct tag value"
E int `json:"e,omitempty, string"` // ERROR "suspicious space found in struct tag value" E int `xml:" f"` // ERROR "suspicious space found in struct tag value"
F int `xml:" f"` // ERROR "suspicious space found in struct tag value" F int `xml:"g "` // ERROR "suspicious space found in struct tag value"
G int `xml:"g "` // ERROR "suspicious space found in struct tag value" G int `xml:"h ,omitempty"` // ERROR "suspicious space found in struct tag value"
H int `xml:"h ,omitempty"` // ERROR "suspicious space found in struct tag value" H int `xml:" i"` // ERROR "suspicious space found in struct tag value"
I int `xml:" i"` // ERROR "suspicious space found in struct tag value" I int `xml:"j "` // ERROR "suspicious space found in struct tag value"
J int `xml:"j "` // ERROR "suspicious space found in struct tag value" J int `xml:"k ,omitempty"` // ERROR "suspicious space found in struct tag value"
K int `xml:"k ,omitempty"` // ERROR "suspicious space found in struct tag value" K int `foo:" doesn't care "`
L int `foo:" doesn't care "`
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment