diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2012-01-25 21:54:22 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2012-01-25 21:54:22 +0000 |
commit | af92e385667da3fc91ac7f9f0867a56c111110b8 (patch) | |
tree | c8e8990a2197e33f6fe50a28a16714aafe982102 /libgo/go/encoding | |
parent | df1304ee03f41aed179545d1e8b4684cfd22bbdf (diff) | |
download | gcc-af92e385667da3fc91ac7f9f0867a56c111110b8.zip gcc-af92e385667da3fc91ac7f9f0867a56c111110b8.tar.gz gcc-af92e385667da3fc91ac7f9f0867a56c111110b8.tar.bz2 |
libgo: Update to weekly.2012-01-20.
From-SVN: r183540
Diffstat (limited to 'libgo/go/encoding')
-rw-r--r-- | libgo/go/encoding/gob/debug.go | 4 | ||||
-rw-r--r-- | libgo/go/encoding/gob/dump.go | 4 | ||||
-rw-r--r-- | libgo/go/encoding/json/encode.go | 14 | ||||
-rw-r--r-- | libgo/go/encoding/json/tagkey_test.go | 13 | ||||
-rw-r--r-- | libgo/go/encoding/xml/marshal_test.go | 17 | ||||
-rw-r--r-- | libgo/go/encoding/xml/read.go | 4 | ||||
-rw-r--r-- | libgo/go/encoding/xml/typeinfo.go | 4 |
7 files changed, 52 insertions, 8 deletions
diff --git a/libgo/go/encoding/gob/debug.go b/libgo/go/encoding/gob/debug.go index b21c7fa..4a61d0f 100644 --- a/libgo/go/encoding/gob/debug.go +++ b/libgo/go/encoding/gob/debug.go @@ -1,3 +1,7 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + package gob // This file is not normally included in the gob package. Used only for debugging the package itself. diff --git a/libgo/go/encoding/gob/dump.go b/libgo/go/encoding/gob/dump.go index 0d0017c..f7d822c 100644 --- a/libgo/go/encoding/gob/dump.go +++ b/libgo/go/encoding/gob/dump.go @@ -1,3 +1,7 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + package main // Need to compile package gob with debug.go to build this program. diff --git a/libgo/go/encoding/json/encode.go b/libgo/go/encoding/json/encode.go index 033da2d..eac14a4 100644 --- a/libgo/go/encoding/json/encode.go +++ b/libgo/go/encoding/json/encode.go @@ -39,6 +39,8 @@ import ( // // String values encode as JSON strings, with each invalid UTF-8 sequence // replaced by the encoding of the Unicode replacement character U+FFFD. +// The angle brackets "<" and ">" are escaped to "\u003c" and "\u003e" +// to keep some browsers from misinterpreting JSON output as HTML. // // Array and slice values encode as JSON arrays, except that // []byte encodes as a base64-encoded string. @@ -77,7 +79,8 @@ import ( // Int64String int64 `json:",string"` // // The key name will be used if it's a non-empty string consisting of -// only Unicode letters, digits, dollar signs, hyphens, and underscores. +// only Unicode letters, digits, dollar signs, percent signs, hyphens, +// underscores and slashes. // // Map values encode as JSON objects. // The map's key type must be string; the object keys are used directly @@ -417,8 +420,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/libgo/go/encoding/json/tagkey_test.go b/libgo/go/encoding/json/tagkey_test.go index 31fe2be..bba5730 100644 --- a/libgo/go/encoding/json/tagkey_test.go +++ b/libgo/go/encoding/json/tagkey_test.go @@ -9,7 +9,7 @@ import ( ) type basicLatin2xTag struct { - V string `json:"$-"` + V string `json:"$%-/"` } type basicLatin3xTag struct { @@ -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 } @@ -49,7 +53,7 @@ type badFormatTag struct { } type badCodeTag struct { - Z string `json:" !\"#%&'()*+,./"` + Z string `json:" !\"#&'()*+,."` } var structTagObjectKeyTests = []struct { @@ -57,7 +61,7 @@ var structTagObjectKeyTests = []struct { value string key string }{ - {basicLatin2xTag{"2x"}, "2x", "$-"}, + {basicLatin2xTag{"2x"}, "2x", "$%-/"}, {basicLatin3xTag{"3x"}, "3x", "0123456789"}, {basicLatin4xTag{"4x"}, "4x", "ABCDEFGHIJKLMO"}, {basicLatin5xTag{"5x"}, "5x", "PQRSTUVWXYZ_"}, @@ -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) } } } diff --git a/libgo/go/encoding/xml/marshal_test.go b/libgo/go/encoding/xml/marshal_test.go index bec5376..f23b2cb 100644 --- a/libgo/go/encoding/xml/marshal_test.go +++ b/libgo/go/encoding/xml/marshal_test.go @@ -150,6 +150,10 @@ type XMLNameWithoutTag struct { Value string ",chardata" } +type NameInField struct { + Foo Name `xml:"ns foo"` +} + type AttrTest struct { Int int `xml:",attr"` Lower int `xml:"int,attr"` @@ -483,6 +487,19 @@ var marshalTests = []struct { UnmarshalOnly: true, }, + // xml.Name works in a plain field as well. + { + Value: &NameInField{Name{Space: "ns", Local: "foo"}}, + ExpectXML: `<NameInField><foo xmlns="ns"></foo></NameInField>`, + }, + + // Marshaling zero xml.Name uses the tag or field name. + { + Value: &NameInField{}, + ExpectXML: `<NameInField><foo xmlns="ns"></foo></NameInField>`, + MarshalOnly: true, + }, + // Test attributes { Value: &AttrTest{ diff --git a/libgo/go/encoding/xml/read.go b/libgo/go/encoding/xml/read.go index dde68de..4419ed1 100644 --- a/libgo/go/encoding/xml/read.go +++ b/libgo/go/encoding/xml/read.go @@ -271,6 +271,10 @@ func (p *Parser) unmarshal(val reflect.Value, start *StartElement) error { case reflect.Struct: sv = v typ := sv.Type() + if typ == nameType { + v.Set(reflect.ValueOf(start.Name)) + break + } tinfo, err = getTypeInfo(typ) if err != nil { return err diff --git a/libgo/go/encoding/xml/typeinfo.go b/libgo/go/encoding/xml/typeinfo.go index 8f79c4e..36b35ed 100644 --- a/libgo/go/encoding/xml/typeinfo.go +++ b/libgo/go/encoding/xml/typeinfo.go @@ -46,6 +46,8 @@ const ( var tinfoMap = make(map[reflect.Type]*typeInfo) var tinfoLock sync.RWMutex +var nameType = reflect.TypeOf(Name{}) + // getTypeInfo returns the typeInfo structure with details necessary // for marshalling and unmarshalling typ. func getTypeInfo(typ reflect.Type) (*typeInfo, error) { @@ -56,7 +58,7 @@ func getTypeInfo(typ reflect.Type) (*typeInfo, error) { return tinfo, nil } tinfo = &typeInfo{} - if typ.Kind() == reflect.Struct { + if typ.Kind() == reflect.Struct && typ != nameType { n := typ.NumField() for i := 0; i < n; i++ { f := typ.Field(i) |