From 4ee51e3ef51a8c395ab15103c059523b64ef72d1 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Wed, 8 Sep 2021 09:23:16 -0400 Subject: [PATCH] Fix atom item with multiple authors not getting converted to string --- lib/parser/atom.ex | 11 +++++------ test/fixtures/atom/multi_author_item.xml | 23 +++++++++++++++++++++++ test/parser/atom_test.exs | 7 +++++++ 3 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 test/fixtures/atom/multi_author_item.xml diff --git a/lib/parser/atom.ex b/lib/parser/atom.ex index f70cc71..16d61d3 100644 --- a/lib/parser/atom.ex +++ b/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) diff --git a/test/fixtures/atom/multi_author_item.xml b/test/fixtures/atom/multi_author_item.xml new file mode 100644 index 0000000..e357ce2 --- /dev/null +++ b/test/fixtures/atom/multi_author_item.xml @@ -0,0 +1,23 @@ + + + + Example Feed + + 2003-12-13T18:30:02Z + urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6 + + + Atom-Powered Robots Run Amok + + urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a + 2003-12-13T18:30:02Z + Some text. + + John Doe + + + Jane Doe + + + + diff --git a/test/parser/atom_test.exs b/test/parser/atom_test.exs index 00dae3c..83a8750 100644 --- a/test/parser/atom_test.exs +++ b/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