aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@golang.org>2012-01-18 19:05:15 -0800
committerBrad Fitzpatrick <bradfitz@golang.org>2012-01-18 19:05:15 -0800
commitb39c883e292a39a0ac05507b5d79d89cc7328836 (patch)
tree0b9ebfee16463594afa380878fec3e7f240930da
parent0d8c6b4fcdcbaa56ce1ccaf6dcd99b58af830c5b (diff)
downloadgo-b39c883e292a39a0ac05507b5d79d89cc7328836.tar.gz
go-b39c883e292a39a0ac05507b5d79d89cc7328836.zip
encoding/json: allow / and % in tag names
Fixes #2718 R=golang-dev, adg CC=golang-dev https://golang.org/cl/5532095
-rw-r--r--src/pkg/encoding/json/encode.go9
-rw-r--r--src/pkg/encoding/json/tagkey_test.go7
2 files changed, 13 insertions, 3 deletions
diff --git a/src/pkg/encoding/json/encode.go b/src/pkg/encoding/json/encode.go
index 727e8174bd..042142d2c5 100644
--- a/src/pkg/encoding/json/encode.go
+++ b/src/pkg/encoding/json/encode.go
@@ -419,8 +419,13 @@ func isValidTag(s string) bool {
return false
}
for _, c := range s {
- if c != '$' && c != '-' && c != '_' && !unicode.IsLetter(c) && !unicode.IsDigit(c) {
- return false
+ switch c {
+ case '$', '-', '_', '/', '%':
+ // Acceptable
+ default:
+ if !unicode.IsLetter(c) && !unicode.IsDigit(c) {
+ return false
+ }
}
}
return true
diff --git a/src/pkg/encoding/json/tagkey_test.go b/src/pkg/encoding/json/tagkey_test.go
index 31fe2be362..1a15241cb0 100644
--- a/src/pkg/encoding/json/tagkey_test.go
+++ b/src/pkg/encoding/json/tagkey_test.go
@@ -36,6 +36,10 @@ type miscPlaneTag struct {
V string `json:"色は匂へど"`
}
+type percentSlashTag struct {
+ V string `json:"text/html%"` // http://golang.org/issue/2718
+}
+
type emptyTag struct {
W string
}
@@ -68,6 +72,7 @@ var structTagObjectKeyTests = []struct {
{misnamedTag{"Animal Kingdom"}, "Animal Kingdom", "X"},
{badFormatTag{"Orfevre"}, "Orfevre", "Y"},
{badCodeTag{"Reliable Man"}, "Reliable Man", "Z"},
+ {percentSlashTag{"brut"}, "brut", "text/html%"},
}
func TestStructTagObjectKey(t *testing.T) {
@@ -88,7 +93,7 @@ func TestStructTagObjectKey(t *testing.T) {
t.Fatalf("Unexpected value: %#q, want %v", s, tt.value)
}
default:
- t.Fatalf("Unexpected key: %#q", i)
+ t.Fatalf("Unexpected key: %#q, from %#q", i, b)
}
}
}