]> Cypherpunks repositories - gostls13.git/commitdiff
encoding/xml: display closing space in error message
authorConstantin Konstantinidis <constantinkonstantinidis@gmail.com>
Sun, 15 Oct 2023 15:58:43 +0000 (17:58 +0200)
committerGopher Robot <gobot@golang.org>
Wed, 28 Feb 2024 20:19:43 +0000 (20:19 +0000)
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>
src/encoding/xml/xml.go
src/encoding/xml/xml_test.go

index a1e63ed30d39db682dea2924107d3618142da052..582cfee222be5ba6753fef06ff47f1bf20d40a56 100644 (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
        }
 
index 2c985f7c70f8327cc3500f9cb11416f53259e300..c3848c387301b6e880a806dc97686a2babde19d2 100644 (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
                }
        }