diff --git a/src/pkg/encoding/xml/read.go b/src/pkg/encoding/xml/read.go
index e97abec55a4..9617150c8f1 100644
--- a/src/pkg/encoding/xml/read.go
+++ b/src/pkg/encoding/xml/read.go
@@ -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(
diff --git a/src/pkg/encoding/xml/read_test.go b/src/pkg/encoding/xml/read_test.go
index d39c2d52a83..fbb7fd5d2f2 100644
--- a/src/pkg/encoding/xml/read_test.go
+++ b/src/pkg/encoding/xml/read_test.go
@@ -245,6 +245,9 @@ const pathTestString = `
C
D
+ <_>
+ E
+
2
@@ -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) {