From 475f3df43fa6f89413bc142c61a5551d3f8bd281 Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Travostino?= Date: Sat, 22 Dec 2012 13:36:55 -0500 Subject: [PATCH] encoding/json: A JSON tag can be any valid JSON string. Fixes #3887. R=golang-dev, daniel.morsing, remyoudompheng, rsc CC=golang-dev https://golang.org/cl/6997045 --- src/pkg/encoding/json/encode.go | 2 +- src/pkg/encoding/json/tagkey_test.go | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/pkg/encoding/json/encode.go b/src/pkg/encoding/json/encode.go index a5803b4623..c3018ad293 100644 --- a/src/pkg/encoding/json/encode.go +++ b/src/pkg/encoding/json/encode.go @@ -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. diff --git a/src/pkg/encoding/json/tagkey_test.go b/src/pkg/encoding/json/tagkey_test.go index da8b12bd8f..23e71c7525 100644 --- a/src/pkg/encoding/json/tagkey_test.go +++ b/src/pkg/encoding/json/tagkey_test.go @@ -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) { -- 2.48.1