Skip to content

Commit

Permalink
Handle Atom links with a text/html type defined
Browse files Browse the repository at this point in the history
  • Loading branch information
fguillot committed Aug 1, 2022
1 parent 071e910 commit 13fa08a
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
78 changes: 78 additions & 0 deletions reader/atom/atom_10_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,84 @@ func TestParseEntryWithRelativeURL(t *testing.T) {
}
}

func TestParseEntryURLWithTextHTMLType(t *testing.T) {
data := `<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Example Feed</title>
<link href="http://example.org/"/>
<entry>
<title>Test</title>
<link href="http://example.org/something.html" type="text/html"/>
<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
<updated>2003-12-13T18:30:02Z</updated>
<summary>Some text.</summary>
</entry>
</feed>`

feed, err := Parse("https://example.net/", bytes.NewBufferString(data))
if err != nil {
t.Fatal(err)
}

if feed.Entries[0].URL != "http://example.org/something.html" {
t.Errorf("Incorrect entry URL, got: %s", feed.Entries[0].URL)
}
}

func TestParseEntryURLWithNoRelAndNoType(t *testing.T) {
data := `<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Example Feed</title>
<link href="http://example.org/"/>
<entry>
<title>Test</title>
<link href="http://example.org/something.html"/>
<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
<updated>2003-12-13T18:30:02Z</updated>
<summary>Some text.</summary>
</entry>
</feed>`

feed, err := Parse("https://example.net/", bytes.NewBufferString(data))
if err != nil {
t.Fatal(err)
}

if feed.Entries[0].URL != "http://example.org/something.html" {
t.Errorf("Incorrect entry URL, got: %s", feed.Entries[0].URL)
}
}

func TestParseEntryURLWithAlternateRel(t *testing.T) {
data := `<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Example Feed</title>
<link href="http://example.org/"/>
<entry>
<title>Test</title>
<link href="http://example.org/something.html" rel="alternate"/>
<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
<updated>2003-12-13T18:30:02Z</updated>
<summary>Some text.</summary>
</entry>
</feed>`

feed, err := Parse("https://example.net/", bytes.NewBufferString(data))
if err != nil {
t.Fatal(err)
}

if feed.Entries[0].URL != "http://example.org/something.html" {
t.Errorf("Incorrect entry URL, got: %s", feed.Entries[0].URL)
}
}

func TestParseEntryTitleWithWhitespaces(t *testing.T) {
data := `<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
Expand Down
2 changes: 1 addition & 1 deletion reader/atom/atom_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (a atomLinks) originalLink() string {
return strings.TrimSpace(link.URL)
}

if link.Rel == "" && link.Type == "" {
if link.Rel == "" && (link.Type == "" || link.Type == "text/html") {
return strings.TrimSpace(link.URL)
}
}
Expand Down

0 comments on commit 13fa08a

Please sign in to comment.