Fix atom item with multiple authors not getting converted to string

This commit is contained in:
Shadowfacts 2021-09-08 09:23:16 -04:00
parent c2323ae19a
commit 4ee51e3ef5
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
3 changed files with 35 additions and 6 deletions

View File

@ -73,12 +73,11 @@ defmodule FeedParser.Parser.Atom do
end
author =
texts('/entry/author/name/text()', entry) ||
feed_author
|> case do
nil -> nil
authors -> Enum.join(authors, ", ")
end
(texts('/entry/author/name/text()', entry) || feed_author)
|> case do
nil -> nil
authors -> Enum.join(authors, ", ")
end
content = text('/entry/content/text()', entry) || text('/entry/summary/text()', entry)

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Example Feed</title>
<link href="http://example.org/"/>
<updated>2003-12-13T18:30:02Z</updated>
<id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>
<entry>
<title>Atom-Powered Robots Run Amok</title>
<link href="http://example.org/2003/12/13/atom03"/>
<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
<updated>2003-12-13T18:30:02Z</updated>
<summary>Some text.</summary>
<author>
<name>John Doe</name>
</author>
<author>
<name>Jane Doe</name>
</author>
</entry>
</feed>

View File

@ -48,4 +48,11 @@ defmodule FeedParser.Parser.AtomTest do
assert {:ok, %FeedParser.Feed{items: items}} = Atom.parse_feed(parsed_data)
assert [%FeedParser.Item{creator: "John Doe, Jane Doe"}] = items
end
test "parses ato item with multiple authors" do
data = File.read!("test/fixtures/atom/multi_author_item.xml")
{true, parsed_data} = Atom.accepts(data, "application/atom+xml")
assert {:ok, %FeedParser.Feed{items: items}} = Atom.parse_feed(parsed_data)
assert [%FeedParser.Item{creator: "John Doe, Jane Doe"}] = items
end
end