aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/vendor
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2020-12-10 22:24:21 -0800
committerIan Lance Taylor <iant@golang.org>2020-12-11 06:46:11 +0000
commit58e381b0b22352dda355f6d95fa101b773766c72 (patch)
treedbb3460ce0122a0328bcb0d9d81b8593970afbc0 /src/cmd/vendor
parente012d0dc34e0c182aed605347fb19c6980b3f8bd (diff)
downloadgo-58e381b0b22352dda355f6d95fa101b773766c72.tar.gz
go-58e381b0b22352dda355f6d95fa101b773766c72.zip
cmd/vet: vendor in x/tools, update structtag vet check
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>
Diffstat (limited to 'src/cmd/vendor')
-rw-r--r--src/cmd/vendor/golang.org/x/tools/go/analysis/passes/structtag/structtag.go94
-rw-r--r--src/cmd/vendor/modules.txt2
2 files changed, 57 insertions, 39 deletions
diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/structtag/structtag.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/structtag/structtag.go
index f0b15051c5..02555648a0 100644
--- a/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/structtag/structtag.go
+++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/structtag/structtag.go
@@ -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
}
diff --git a/src/cmd/vendor/modules.txt b/src/cmd/vendor/modules.txt
index b549258cfa..4e47f41855 100644
--- a/src/cmd/vendor/modules.txt
+++ b/src/cmd/vendor/modules.txt
@@ -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