From: Francesc Campoy Flores Date: Thu, 24 Aug 2017 17:07:15 +0000 (-0700) Subject: cmd/vet: check only for ASCII spaces (0x20) in struct tags X-Git-Tag: go1.10beta1~1383 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=e258249c247d7135f164f4f0b3abb29bebe75767;p=gostls13.git 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 TryBot-Result: Gobot Gobot Reviewed-by: Rob Pike --- diff --git a/src/cmd/vet/structtag.go b/src/cmd/vet/structtag.go index b50417b37d..eeef0ec110 100644 --- a/src/cmd/vet/structtag.go +++ b/src/cmd/vet/structtag.go @@ -13,7 +13,6 @@ import ( "reflect" "strconv" "strings" - "unicode" ) func init() { @@ -195,7 +194,7 @@ func validateStructTag(tag string) error { value = value[comma+1:] } - if strings.IndexFunc(value, unicode.IsSpace) >= 0 { + if strings.IndexByte(value, ' ') >= 0 { return errTagValueSpace } } diff --git a/src/cmd/vet/testdata/structtag.go b/src/cmd/vet/testdata/structtag.go index ae9a744de7..cdd29bb94a 100644 --- a/src/cmd/vet/testdata/structtag.go +++ b/src/cmd/vet/testdata/structtag.go @@ -83,15 +83,14 @@ type DuplicateJSONFields struct { type UnexpectedSpacetest struct { A int `json:"a,omitempty"` - 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" - D int `json:"d ,omitempty"` - E int `json:"e,omitempty, string"` // ERROR "suspicious space found in struct tag value" - F int `xml:" f"` // ERROR "suspicious space found in struct tag value" - G int `xml:"g "` // ERROR "suspicious space found in struct tag value" - H int `xml:"h ,omitempty"` // ERROR "suspicious space found in struct tag value" - I int `xml:" i"` // ERROR "suspicious space found in struct tag value" - J int `xml:"j "` // ERROR "suspicious space found in struct tag value" - K int `xml:"k ,omitempty"` // ERROR "suspicious space found in struct tag value" - L int `foo:" doesn't care "` + B int `json:"b, omitempty"` // ERROR "suspicious space found in struct tag value" + C int `json:"d ,omitempty"` + D 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:"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:" i"` // ERROR "suspicious space found in struct tag value" + I 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 `foo:" doesn't care "` }