Commit 1371ac2f authored by David Crawshaw's avatar David Crawshaw Committed by Russ Cox

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

R=rsc, nigeltao
CC=golang-dev
https://golang.org/cl/5298061
parent ad0e8b31
......@@ -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(
......
......@@ -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) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment