Przeglądaj źródła

Handle Atom links with a text/html type defined

Frédéric Guillot 3 lat temu
rodzic
commit
13fa08ad39
2 zmienionych plików z 79 dodań i 1 usunięć
  1. 78 0
      reader/atom/atom_10_test.go
  2. 1 1
      reader/atom/atom_common.go

+ 78 - 0
reader/atom/atom_10_test.go

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

+ 1 - 1
reader/atom/atom_common.go

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