]> Cypherpunks repositories - gostls13.git/commitdiff
encoding/json: allow / and % in tag names
authorBrad Fitzpatrick <bradfitz@golang.org>
Thu, 19 Jan 2012 03:05:15 +0000 (19:05 -0800)
committerBrad Fitzpatrick <bradfitz@golang.org>
Thu, 19 Jan 2012 03:05:15 +0000 (19:05 -0800)
Fixes #2718

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/5532095

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

index 727e8174bdb8dc5b1f92ea14217077ce10f8e014..042142d2c53d26a492453576f71d5a1a40a95ac3 100644 (file)
@@ -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
index 31fe2be3621042a00f4da41fc75c3a86208ada5c..1a15241cb0c3688e16b7777a537b5c2130783438 100644 (file)
@@ -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)
                        }
                }
        }