mirror of
https://github.com/nkanaev/yarr.git
synced 2025-05-25 05:29:20 +00:00
parser fixes
This commit is contained in:
parent
cc51fe01c2
commit
fafa6286d4
@ -23,7 +23,7 @@ type atomEntry struct {
|
|||||||
Published string `xml:"published"`
|
Published string `xml:"published"`
|
||||||
Updated string `xml:"updated"`
|
Updated string `xml:"updated"`
|
||||||
Links atomLinks `xml:"link"`
|
Links atomLinks `xml:"link"`
|
||||||
Content atomText `xml:"content"`
|
Content atomText `xml:"http://www.w3.org/2005/Atom content"`
|
||||||
media
|
media
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,3 +56,24 @@ func TestAtom(t *testing.T) {
|
|||||||
t.Fatal("invalid atom")
|
t.Fatal("invalid atom")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAtomClashingNamespaces(t *testing.T) {
|
||||||
|
have, err := Parse(strings.NewReader(`
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<feed xmlns="http://www.w3.org/2005/Atom">
|
||||||
|
<entry>
|
||||||
|
<content>atom content</content>
|
||||||
|
<media:content xmlns:media="http://search.yahoo.com/mrss/" />
|
||||||
|
</entry>
|
||||||
|
</feed>
|
||||||
|
`))
|
||||||
|
want := &Feed{Items: []Item{{Content: "atom content"}}}
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if !reflect.DeepEqual(want, have) {
|
||||||
|
t.Logf("want: %#v", want)
|
||||||
|
t.Logf("have: %#v", have)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -46,11 +46,11 @@ func Parse(r io.Reader) (*Feed, error) {
|
|||||||
lookup := make([]byte, 1024)
|
lookup := make([]byte, 1024)
|
||||||
n, err := io.ReadFull(r, lookup)
|
n, err := io.ReadFull(r, lookup)
|
||||||
switch {
|
switch {
|
||||||
case err != nil:
|
|
||||||
return nil, err
|
|
||||||
case err == io.ErrUnexpectedEOF:
|
case err == io.ErrUnexpectedEOF:
|
||||||
lookup = lookup[:n]
|
lookup = lookup[:n]
|
||||||
r = bytes.NewReader(lookup)
|
r = bytes.NewReader(lookup)
|
||||||
|
case err != nil:
|
||||||
|
return nil, err
|
||||||
default:
|
default:
|
||||||
r = io.MultiReader(bytes.NewReader(lookup), r)
|
r = io.MultiReader(bytes.NewReader(lookup), r)
|
||||||
}
|
}
|
||||||
|
@ -77,3 +77,18 @@ func TestParse(t *testing.T) {
|
|||||||
t.Fatal("invalid content")
|
t.Fatal("invalid content")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParseShortFeed(t *testing.T) {
|
||||||
|
have, err := Parse(strings.NewReader(
|
||||||
|
`<?xml version="1.0"?><feed xmlns="http://www.w3.org/2005/Atom"></feed>`,
|
||||||
|
))
|
||||||
|
want := &Feed{}
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if !reflect.DeepEqual(want, have) {
|
||||||
|
t.Logf("want: %#v", want)
|
||||||
|
t.Logf("have: %#v", have)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -12,13 +12,6 @@ type mediaGroup struct {
|
|||||||
MediaDescriptions []mediaDescription `xml:"http://search.yahoo.com/mrss/ description"`
|
MediaDescriptions []mediaDescription `xml:"http://search.yahoo.com/mrss/ description"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type mediaContent struct {
|
|
||||||
URL string `xml:"url,attr"`
|
|
||||||
Type string `xml:"type,attr"`
|
|
||||||
FileSize string `xml:"fileSize,attr"`
|
|
||||||
Medium string `xml:"medium,attr"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type mediaThumbnail struct {
|
type mediaThumbnail struct {
|
||||||
URL string `xml:"url,attr"`
|
URL string `xml:"url,attr"`
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user