fix: String() handled ns prefixes incorrectly

Previously parsing a document like this:

  <root xmlns:foo='http:/example.org/foo' foo:bar='1'/>

Would produce an incorrect document when turning it back into a string:

  <root xmlns:foo='http:/example.org/foo' http:/example.org/foo:bar='1'/>

This patch fixes this by implementing a proper lookup for namespace
prefixes.
This commit is contained in:
Felix Geisendörfer 2013-09-04 00:35:22 +02:00
parent 089e94f17d
commit 08c0943149
3 changed files with 47 additions and 1 deletions

View file

@ -136,3 +136,26 @@ func TestUnmarshal(t *testing.T) {
return
}
}
func TestString(t *testing.T) {
doc := New()
err := doc.LoadFile("test3.xml", nil)
if err != nil {
t.Errorf("LoadFile(): %s", err)
return
}
expected := `<root xmlns:foo="http:/example.org/foo">
<child foo:bar="1">
<grandchild xmlns:foo="">
<great-grandchild bar="2" />
</grandchild>
</child>
</root>
`
if got := doc.Root.String(); got != expected {
t.Fatalf("expected: %s\ngot: %s\n", expected, got)
}
}