]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/vet: vendor in x/tools, update structtag vet check
authorIan Lance Taylor <iant@golang.org>
Fri, 11 Dec 2020 06:24:21 +0000 (22:24 -0800)
committerIan Lance Taylor <iant@golang.org>
Fri, 11 Dec 2020 06:46:11 +0000 (06:46 +0000)
For #40281
Fixes #43083

Change-Id: I50cb4db916587a6660c7f6e71f41f02334081510
Reviewed-on: https://go-review.googlesource.com/c/go/+/277076
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>

src/cmd/go.mod
src/cmd/go.sum
src/cmd/vendor/golang.org/x/tools/go/analysis/passes/structtag/structtag.go
src/cmd/vendor/modules.txt

index c7d43873efe821e202d5e97bc8b163b28f228741..031b8d4ab75b1c62687a0ebdd9b87a92be227cab 100644 (file)
@@ -8,5 +8,5 @@ require (
        golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897
        golang.org/x/mod v0.4.0
        golang.org/x/sys v0.0.0-20201204225414-ed752295db88 // indirect
-       golang.org/x/tools v0.0.0-20201208211828-de58e7c01d49
+       golang.org/x/tools v0.0.0-20201211025543-abf6a1d87e11
 )
index 30edf77282df6d3f59e4abc8adc1dd95922ea168..2fde9445f6507f7063329bc02557776803fdb5e3 100644 (file)
@@ -31,8 +31,8 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
 golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
 golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
-golang.org/x/tools v0.0.0-20201208211828-de58e7c01d49 h1:K1QAOVIWIvmQ66F1Z3AEa9Wzp0bj+xU3YzLkvROk2Ds=
-golang.org/x/tools v0.0.0-20201208211828-de58e7c01d49/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
+golang.org/x/tools v0.0.0-20201211025543-abf6a1d87e11 h1:9j/upNXDRpADUw2RpUfJ7E7GHtfhDih62kX6JM8vs2c=
+golang.org/x/tools v0.0.0-20201211025543-abf6a1d87e11/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
 golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
index f0b15051c52eacc1cc5fd6912bfa03dcb3ea7558..02555648a0bdd4f34446127e9fbb87764151514d 100644 (file)
@@ -207,12 +207,12 @@ var (
 )
 
 // validateStructTag parses the struct tag and returns an error if it is not
-// in the canonical format, which is a space-separated list of key:"value"
-// settings. The value may contain spaces.
+// in the canonical format, as defined by reflect.StructTag.
 func validateStructTag(tag string) error {
        // This code is based on the StructTag.Get code in package reflect.
 
        n := 0
+       var keys []string
        for ; tag != ""; n++ {
                if n > 0 && tag != "" && tag[0] != ' ' {
                        // More restrictive than reflect, but catches likely mistakes
@@ -240,14 +240,27 @@ func validateStructTag(tag string) error {
                if i == 0 {
                        return errTagKeySyntax
                }
-               if i+1 >= len(tag) || tag[i] != ':' {
+               if i+1 >= len(tag) || tag[i] < ' ' || tag[i] == 0x7f {
                        return errTagSyntax
                }
-               if tag[i+1] != '"' {
+               key := tag[:i]
+               keys = append(keys, key)
+               tag = tag[i:]
+
+               // If we found a space char here - assume that we have a tag with
+               // multiple keys.
+               if tag[0] == ' ' {
+                       continue
+               }
+
+               // Spaces were filtered above so we assume that here we have
+               // only valid tag value started with `:"`.
+               if tag[0] != ':' || tag[1] != '"' {
                        return errTagValueSyntax
                }
-               key := tag[:i]
-               tag = tag[i+1:]
+
+               // Remove the colon leaving tag at the start of the quoted string.
+               tag = tag[1:]
 
                // Scan quoted string to find value.
                i = 1
@@ -263,51 +276,56 @@ func validateStructTag(tag string) error {
                qvalue := tag[:i+1]
                tag = tag[i+1:]
 
-               value, err := strconv.Unquote(qvalue)
+               wholeValue, err := strconv.Unquote(qvalue)
                if err != nil {
                        return errTagValueSyntax
                }
 
-               if !checkTagSpaces[key] {
-                       continue
-               }
-
-               switch key {
-               case "xml":
-                       // If the first or last character in the XML tag is a space, it is
-                       // suspicious.
-                       if strings.Trim(value, " ") != value {
-                               return errTagValueSpace
+               for _, key := range keys {
+                       if !checkTagSpaces[key] {
+                               continue
                        }
 
-                       // If there are multiple spaces, they are suspicious.
-                       if strings.Count(value, " ") > 1 {
-                               return errTagValueSpace
-                       }
+                       value := wholeValue
+                       switch key {
+                       case "xml":
+                               // If the first or last character in the XML tag is a space, it is
+                               // suspicious.
+                               if strings.Trim(value, " ") != value {
+                                       return errTagValueSpace
+                               }
 
-                       // If there is no comma, skip the rest of the checks.
-                       comma := strings.IndexRune(value, ',')
-                       if comma < 0 {
-                               continue
+                               // If there are multiple spaces, they are suspicious.
+                               if strings.Count(value, " ") > 1 {
+                                       return errTagValueSpace
+                               }
+
+                               // If there is no comma, skip the rest of the checks.
+                               comma := strings.IndexRune(value, ',')
+                               if comma < 0 {
+                                       continue
+                               }
+
+                               // If the character before a comma is a space, this is suspicious.
+                               if comma > 0 && value[comma-1] == ' ' {
+                                       return errTagValueSpace
+                               }
+                               value = value[comma+1:]
+                       case "json":
+                               // JSON allows using spaces in the name, so skip it.
+                               comma := strings.IndexRune(value, ',')
+                               if comma < 0 {
+                                       continue
+                               }
+                               value = value[comma+1:]
                        }
 
-                       // If the character before a comma is a space, this is suspicious.
-                       if comma > 0 && value[comma-1] == ' ' {
+                       if strings.IndexByte(value, ' ') >= 0 {
                                return errTagValueSpace
                        }
-                       value = value[comma+1:]
-               case "json":
-                       // JSON allows using spaces in the name, so skip it.
-                       comma := strings.IndexRune(value, ',')
-                       if comma < 0 {
-                               continue
-                       }
-                       value = value[comma+1:]
                }
 
-               if strings.IndexByte(value, ' ') >= 0 {
-                       return errTagValueSpace
-               }
+               keys = keys[:0]
        }
        return nil
 }
index b549258cfa28c51e59e5db37593e847be66bc65e..4e47f41855ef24ad4e83a7220700a0173e30c02e 100644 (file)
@@ -44,7 +44,7 @@ golang.org/x/mod/zip
 golang.org/x/sys/internal/unsafeheader
 golang.org/x/sys/unix
 golang.org/x/sys/windows
-# golang.org/x/tools v0.0.0-20201208211828-de58e7c01d49
+# golang.org/x/tools v0.0.0-20201211025543-abf6a1d87e11
 ## explicit
 golang.org/x/tools/go/analysis
 golang.org/x/tools/go/analysis/internal/analysisflags