1
0
mirror of https://github.com/golang/go synced 2024-11-26 02:07:57 -07:00

encoding/xml: display closing space in error message

Fixes #48890

Change-Id: I7644d091ad92663bda52ef4905239ec499ef9207
Reviewed-on: https://go-review.googlesource.com/c/go/+/535535
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
This commit is contained in:
Constantin Konstantinidis 2023-10-15 17:58:43 +02:00 committed by Gopher Robot
parent 6e49ccc7db
commit b426e9797f
2 changed files with 8 additions and 2 deletions

View File

@ -493,8 +493,12 @@ func (d *Decoder) popElement(t *EndElement) bool {
d.err = d.syntaxError("element <" + s.name.Local + "> closed by </" + name.Local + ">")
return false
case s.name.Space != name.Space:
ns := name.Space
if name.Space == "" {
ns = `""`
}
d.err = d.syntaxError("element <" + s.name.Local + "> in space " + s.name.Space +
" closed by </" + name.Local + "> in space " + name.Space)
" closed by </" + name.Local + "> in space " + ns)
return false
}

View File

@ -1346,6 +1346,8 @@ func TestParseErrors(t *testing.T) {
{withDefaultHeader(`<!- not ok -->`), `invalid sequence <!- not part of <!--`},
{withDefaultHeader(`<!-? not ok -->`), `invalid sequence <!- not part of <!--`},
{withDefaultHeader(`<![not ok]>`), `invalid <![ sequence`},
{withDefaultHeader(`<zzz:foo xmlns:zzz="http://example.com"><bar>baz</bar></foo>`),
`element <foo> in space zzz closed by </foo> in space ""`},
{withDefaultHeader("\xf1"), `invalid UTF-8`},
// Header-related errors.
@ -1379,7 +1381,7 @@ func TestParseErrors(t *testing.T) {
continue
}
if !strings.Contains(err.Error(), test.err) {
t.Errorf("parse %s: can't find %q error sudbstring\nerror: %q", test.src, test.err, err)
t.Errorf("parse %s: can't find %q error substring\nerror: %q", test.src, test.err, err)
continue
}
}