]> Cypherpunks repositories - gostls13.git/commitdiff
encoding/json: allow semicolon in field key / struct tag
authorSean Liao <seankhliao@gmail.com>
Thu, 21 May 2020 15:52:33 +0000 (17:52 +0200)
committerDaniel Martí <mvdan@mvdan.cc>
Thu, 24 Sep 2020 18:05:54 +0000 (18:05 +0000)
Allow ';' as a valid character for json field keys and struct tags.

Fixes #39189

Change-Id: I4b602a1b0674ff028db07623682f0d1e8e9fd6c9
Reviewed-on: https://go-review.googlesource.com/c/go/+/234818
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Giovanni Bajo <rasky@develer.com>
Trust: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
src/encoding/json/encode.go
src/encoding/json/tagkey_test.go

index 578d551102de47da3bc9f38b143f7d968f34c278..c2d191442c83cd864f1fa2921c4539fa7d3a9291 100644 (file)
@@ -946,7 +946,7 @@ func isValidTag(s string) bool {
        }
        for _, c := range s {
                switch {
-               case strings.ContainsRune("!#$%&()*+-./:<=>?@[]^_{|}~ ", c):
+               case strings.ContainsRune("!#$%&()*+-./:;<=>?@[]^_{|}~ ", c):
                        // Backslash and quote chars are reserved, but
                        // otherwise any punctuation chars are allowed
                        // in a tag name.
index f77c49c76471e994ed53a6b955d6a16fdbac13c4..bbb4e6a28d24fa719dbbc172cb66c8594a210977 100644 (file)
@@ -41,7 +41,7 @@ type percentSlashTag struct {
 }
 
 type punctuationTag struct {
-       V string `json:"!#$%&()*+-./:<=>?@[]^_{|}~"` // https://golang.org/issue/3546
+       V string `json:"!#$%&()*+-./:;<=>?@[]^_{|}~ "` // https://golang.org/issue/3546
 }
 
 type dashTag struct {
@@ -90,7 +90,7 @@ var structTagObjectKeyTests = []struct {
        {badFormatTag{"Orfevre"}, "Orfevre", "Y"},
        {badCodeTag{"Reliable Man"}, "Reliable Man", "Z"},
        {percentSlashTag{"brut"}, "brut", "text/html%"},
-       {punctuationTag{"Union Rags"}, "Union Rags", "!#$%&()*+-./:<=>?@[]^_{|}~"},
+       {punctuationTag{"Union Rags"}, "Union Rags", "!#$%&()*+-./:;<=>?@[]^_{|}~ "},
        {spaceTag{"Perreddu"}, "Perreddu", "With space"},
        {unicodeTag{"Loukanikos"}, "Loukanikos", "Ελλάδα"},
 }