Browse Source

Fix atom item with multiple authors not getting converted to string

master
Shadowfacts 2 months ago
parent
commit
4ee51e3ef5
Signed by: shadowfacts GPG Key ID: 94A5AB95422746E5
  1. 11
      lib/parser/atom.ex
  2. 23
      test/fixtures/atom/multi_author_item.xml
  3. 7
      test/parser/atom_test.exs

11
lib/parser/atom.ex

@ -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)

23
test/fixtures/atom/multi_author_item.xml

@ -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>

7
test/parser/atom_test.exs

@ -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

Loading…
Cancel
Save