]> Cypherpunks repositories - gostls13.git/commitdiff
encoding/json: A JSON tag can be any valid JSON string.
authorStéphane Travostino <stephane.travostino@gmail.com>
Sat, 22 Dec 2012 18:36:55 +0000 (13:36 -0500)
committerRuss Cox <rsc@golang.org>
Sat, 22 Dec 2012 18:36:55 +0000 (13:36 -0500)
Fixes #3887.

R=golang-dev, daniel.morsing, remyoudompheng, rsc
CC=golang-dev
https://golang.org/cl/6997045

src/pkg/encoding/json/encode.go
src/pkg/encoding/json/tagkey_test.go

index a5803b4623d3c402b78e4ab9567bf6c6d7f0d825..c3018ad2932a671a8427d4e2677fa903f87d14d9 100644 (file)
@@ -437,7 +437,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 da8b12bd8fb4a8f65c21e918cfdf6b721aec0895..23e71c7525a5c3b6dfef9536d4ccd880340a3270 100644 (file)
@@ -60,6 +60,14 @@ type badCodeTag struct {
        Z string `json:" !\"#&'()*+,."`
 }
 
+type spaceTag struct {
+       Q string `json:"With space"`
+}
+
+type unicodeTag struct {
+       W string `json:"Ελλάδα"`
+}
+
 var structTagObjectKeyTests = []struct {
        raw   interface{}
        value string
@@ -78,6 +86,8 @@ var structTagObjectKeyTests = []struct {
        {badCodeTag{"Reliable Man"}, "Reliable Man", "Z"},
        {percentSlashTag{"brut"}, "brut", "text/html%"},
        {punctuationTag{"Union Rags"}, "Union Rags", "!#$%&()*+-./:<=>?@[]^_{|}~"},
+       {spaceTag{"Perreddu"}, "Perreddu", "With space"},
+       {unicodeTag{"Loukanikos"}, "Loukanikos", "Ελλάδα"},
 }
 
 func TestStructTagObjectKey(t *testing.T) {