Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic with atom:link element #8

Closed
vanbroup opened this issue Oct 12, 2021 · 2 comments
Closed

Panic with atom:link element #8

vanbroup opened this issue Oct 12, 2021 · 2 comments

Comments

@vanbroup
Copy link
Contributor

A panic is triggered while decoding atom document with:

<atom:link href="http://www.example.com/rss.xml" rel="self" type="application/rss+xml" />
panic: interface conversion: interface {} is map[string]interface {}, not string

goroutine 1 [running]:
github.com/sbabiv/xml2map.setNodeValue(0xc000060230)
	/tmp/gopath700616318/pkg/mod/github.com/sbabiv/[email protected]/decoder.go:138 +0x965
github.com/sbabiv/xml2map.(*Decoder).Decode(0xc000086f40)
	/tmp/gopath700616318/pkg/mod/github.com/sbabiv/[email protected]/decoder.go:109 +0x2af
main.main()
	/tmp/sandbox2063523566/prog.go:29 +0xb6

Removing the :link suffix from the element resolves the issue, see also this example:

https://play.golang.org/p/E8qc16pry6-

@vanbroup
Copy link
Contributor Author

The problem is caused by the namespace which is ignored by the decoder:

<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>example.com RSS</title>
        <link>https://www.example.com/</link>
        <description>A cool website</description>
        <atom:link href="http://www.example.com/rss.xml" rel="self" type="application/rss+xml" />
        <item>
            <title>Cool Article</title>
            <link>https://www.example.com/cool-article</link>
            <guid>https://www.example.com/cool-article</guid>
            <pubDate>Sun, 10 Dec 2017 05:00:00 GMT</pubDate>
            <description>My cool article description</description>
        </item>
    </channel>
</rss>

The two nodes below are bode decoded as "link", where in the default namespace link is just a string, but in the atom namespace link is a map (because of its attributes), which is causing the panic.

        <link>https://www.example.com/</link>
        <atom:link href="http://www.example.com/rss.xml" rel="self" type="application/rss+xml" />

@sbabiv
Copy link
Owner

sbabiv commented Dec 7, 2021

@vanbroup thanks for the fix. merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants