mirror of
https://github.com/golang/go
synced 2024-11-18 19:44:46 -07:00
encoding/xml: overriding by empty namespace when no new name declaration
The unmarshal and marshal XML text should be consistent if not modified deserialize variable.
Fixes #61881
Change-Id: I475f7b05211b618685597d3ff20b97e3bbeaf8f8
GitHub-Last-Rev: 6831c770c3
GitHub-Pull-Request: golang/go#58401
Reviewed-on: https://go-review.googlesource.com/c/go/+/466295
Reviewed-by: ri xu <xuri.me@gmail.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Russ Cox <rsc@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
dffc47e75a
commit
140266fe75
@ -543,8 +543,9 @@ func (p *printer) marshalValue(val reflect.Value, finfo *fieldInfo, startTemplat
|
||||
}
|
||||
}
|
||||
|
||||
// If a name was found, namespace is overridden with an empty space
|
||||
// If a empty name was found, namespace is overridden with an empty space
|
||||
if tinfo.xmlname != nil && start.Name.Space == "" &&
|
||||
tinfo.xmlname.xmlns == "" && tinfo.xmlname.name == "" &&
|
||||
len(p.tags) != 0 && p.tags[len(p.tags)-1].Space != "" {
|
||||
start.Attr = append(start.Attr, Attr{Name{"", xmlnsPrefix}, ""})
|
||||
}
|
||||
|
@ -1064,14 +1064,19 @@ func TestIssue7113(t *testing.T) {
|
||||
XMLName Name `xml:""` // Sets empty namespace
|
||||
}
|
||||
|
||||
type D struct {
|
||||
XMLName Name `xml:"d"`
|
||||
}
|
||||
|
||||
type A struct {
|
||||
XMLName Name `xml:""`
|
||||
C C `xml:""`
|
||||
D D
|
||||
}
|
||||
|
||||
var a A
|
||||
structSpace := "b"
|
||||
xmlTest := `<A xmlns="` + structSpace + `"><C xmlns=""></C></A>`
|
||||
xmlTest := `<A xmlns="` + structSpace + `"><C xmlns=""></C><d></d></A>`
|
||||
t.Log(xmlTest)
|
||||
err := Unmarshal([]byte(xmlTest), &a)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user