Skip to content

Commit 41f7f67

Browse files
seankhliaomvdan
authored andcommitted
encoding/json: allow semicolon in field key / struct tag
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í <[email protected]> TryBot-Result: Go Bot <[email protected]> Trust: Giovanni Bajo <[email protected]> Trust: Daniel Martí <[email protected]> Reviewed-by: Daniel Martí <[email protected]>
1 parent fcd2fa5 commit 41f7f67

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

json/encode.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ func isValidTag(s string) bool {
946946
}
947947
for _, c := range s {
948948
switch {
949-
case strings.ContainsRune("!#$%&()*+-./:<=>?@[]^_{|}~ ", c):
949+
case strings.ContainsRune("!#$%&()*+-./:;<=>?@[]^_{|}~ ", c):
950950
// Backslash and quote chars are reserved, but
951951
// otherwise any punctuation chars are allowed
952952
// in a tag name.

json/tagkey_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type percentSlashTag struct {
4141
}
4242

4343
type punctuationTag struct {
44-
V string `json:"!#$%&()*+-./:<=>?@[]^_{|}~"` // https://golang.org/issue/3546
44+
V string `json:"!#$%&()*+-./:;<=>?@[]^_{|}~ "` // https://golang.org/issue/3546
4545
}
4646

4747
type dashTag struct {
@@ -90,7 +90,7 @@ var structTagObjectKeyTests = []struct {
9090
{badFormatTag{"Orfevre"}, "Orfevre", "Y"},
9191
{badCodeTag{"Reliable Man"}, "Reliable Man", "Z"},
9292
{percentSlashTag{"brut"}, "brut", "text/html%"},
93-
{punctuationTag{"Union Rags"}, "Union Rags", "!#$%&()*+-./:<=>?@[]^_{|}~"},
93+
{punctuationTag{"Union Rags"}, "Union Rags", "!#$%&()*+-./:;<=>?@[]^_{|}~ "},
9494
{spaceTag{"Perreddu"}, "Perreddu", "With space"},
9595
{unicodeTag{"Loukanikos"}, "Loukanikos", "Ελλάδα"},
9696
}

0 commit comments

Comments
 (0)