xml: allow parsing of <_> </_>.

R=rsc, nigeltao
CC=golang-dev
https://golang.org/cl/5298061
This commit is contained in:
David Crawshaw 2011-11-07 10:47:44 -05:00 committed by Russ Cox
parent ad0e8b31d8
commit 1371ac2f0b
2 changed files with 11 additions and 2 deletions

View file

@ -201,8 +201,8 @@ func (p *Parser) Unmarshal(val interface{}, start *StartElement) error {
func fieldName(original string) string {
var i int
//remove leading underscores
for i = 0; i < len(original) && original[i] == '_'; i++ {
//remove leading underscores, without exhausting all characters
for i = 0; i < len(original)-1 && original[i] == '_'; i++ {
}
return strings.Map(

View file

@ -245,6 +245,9 @@ const pathTestString = `
<Value>C</Value>
<Value>D</Value>
</Item1>
<_>
<value>E</value>
</_>
</items>
<after>2</after>
</result>
@ -279,11 +282,17 @@ type PathTestD struct {
Before, After string
}
type PathTestE struct {
Underline string `xml:"items>_>value"`
Before, After string
}
var pathTests = []interface{}{
&PathTestA{Items: []PathTestItem{{"A"}, {"D"}}, Before: "1", After: "2"},
&PathTestB{Other: []PathTestItem{{"A"}, {"D"}}, Before: "1", After: "2"},
&PathTestC{Values1: []string{"A", "C", "D"}, Values2: []string{"B"}, Before: "1", After: "2"},
&PathTestD{Other: PathTestSet{Item1: []PathTestItem{{"A"}, {"D"}}}, Before: "1", After: "2"},
&PathTestE{Underline: "E", Before: "1", After: "2"},
}
func TestUnmarshalPaths(t *testing.T) {