]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/vet: check only for ASCII spaces (0x20) in struct tags
authorFrancesc Campoy Flores <campoy@golang.org>
Thu, 24 Aug 2017 17:07:15 +0000 (10:07 -0700)
committerFrancesc Campoy Flores <campoy@golang.org>
Thu, 24 Aug 2017 22:07:06 +0000 (22:07 +0000)
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: Rob Pike <r@golang.org>
src/cmd/vet/structtag.go
src/cmd/vet/testdata/structtag.go

index b50417b37db6a64b0231da6a978d4cad2e447051..eeef0ec1107eaf051d513961f14e804325912804 100644 (file)
@@ -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
                }
        }
index ae9a744de7560bb975426ace9de6b35790a3fef0..cdd29bb94a7a659ff6b655683e84d15b76271544 100644 (file)
@@ -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 "`
 }