Repository: mmcdole/gofeed
Pull request #157 (2020-10-01 17:51:57)

Add two more date formats
Just adds a couple more date formats I encountered:

```
"Mon Jan 02 2006 15:04:05 GMT-0700 (MST)" // https://code.visualstudio.com/feed.xml
"Mon, 02 Jan 2006 15:4:5 Z"               // https://distill.pub/rss.xml
```

Hopefully you don't mind extending this list.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/33868882/badge)](https://coveralls.io/builds/33868882)

Coverage remained the same at 73.323% when pulling **087c0702f2eef9f5b3a818bdded64abb2076cf0f on nikstar:master** into **d1e28ead8578a417e353eb80b5c63074a64df2de on mmcdole:master**.


Patch:
diff --git a/detector.go b/detector.go
index b3853b8..f8ae4df 100644
--- a/detector.go
+++ b/detector.go
@@ -33,15 +33,16 @@ func DetectFeedType(feed io.Reader) FeedType {
 	buffer := new(bytes.Buffer)
 	buffer.ReadFrom(feed)
 
-	// remove leading whitespace (if exists)
 	var firstChar byte
 	loop: for {
 		ch, err := buffer.ReadByte()
 		if err != nil {
 			return FeedTypeUnknown
 		}
+		// ignore leading whitespace & byte order marks
 		switch ch {
 		case ' ', '\r', '\n', '\t':
+		case 0xFE, 0xFF, 0x00, 0xEF, 0xBB, 0xBF:  // utf 8-16-32 bom
 		default:
 			firstChar = ch
 			buffer.UnreadByte()
diff --git a/internal/shared/dateparser.go b/internal/shared/dateparser.go
index 59a252f..561bd1d 100644
--- a/internal/shared/dateparser.go
+++ b/internal/shared/dateparser.go
@@ -23,6 +23,7 @@ var dateFormats = []string{
 	"Mon Jan 2 15:04 2006",
 	"Mon Jan 02, 2006 3:04 pm",
 	"Mon Jan 02 2006 15:04:05 -0700",
+	"Mon Jan 02 2006 15:04:05 GMT-0700 (MST)",
 	"Monday, January 2, 2006 03:04 PM",
 	"Monday, January 2, 2006",
 	"Monday, January 02, 2006",
@@ -64,6 +65,7 @@ var dateFormats = []string{
 	"Mon, 02 Jan 2006 15:04:05 -07",
 	"Mon, 02 Jan 2006 15:04:05 00",
 	"Mon, 02 Jan 2006 15:04:05",
+	"Mon, 02 Jan 2006 15:4:5 Z",
 	"Mon, 02 Jan 2006",
 	"January 2, 2006 3:04 PM",
 	"January 2, 2006, 3:04 p.m.",


Test patch:
diff --git a/detector_test.go b/detector_test.go
index f3eb059..d438bf7 100644
--- a/detector_test.go
+++ b/detector_test.go
@@ -19,6 +19,7 @@ func TestDetectFeedType(t *testing.T) {
 		{"atom03_feed.xml", gofeed.FeedTypeAtom},
 		{"atom10_feed.xml", gofeed.FeedTypeAtom},
 		{"rss_feed.xml", gofeed.FeedTypeRSS},
+		{"rss_feed_bom.xml", gofeed.FeedTypeRSS},
 		{"rss_feed_leading_spaces.xml", gofeed.FeedTypeRSS},
 		{"rdf_feed.xml", gofeed.FeedTypeRSS},
 		{"unknown_feed.xml", gofeed.FeedTypeUnknown},
diff --git a/parser_test.go b/parser_test.go
index b30959c..287b82d 100644
--- a/parser_test.go
+++ b/parser_test.go
@@ -27,6 +27,7 @@ func TestParser_Parse(t *testing.T) {
 		{"atom03_feed.xml", "atom", "Feed Title", false},
 		{"atom10_feed.xml", "atom", "Feed Title", false},
 		{"rss_feed.xml", "rss", "Feed Title", false},
+		{"rss_feed_bom.xml", "rss", "Feed Title", false},
 		{"rss_feed_leading_spaces.xml", "rss", "Feed Title", false},
 		{"rdf_feed.xml", "rss", "Feed Title", false},
 		{"sample.json", "json", "title", false},
@@ -68,6 +69,7 @@ func TestParser_ParseString(t *testing.T) {
 		{"atom03_feed.xml", "atom", "Feed Title", false},
 		{"atom10_feed.xml", "atom", "Feed Title", false},
 		{"rss_feed.xml", "rss", "Feed Title", false},
+		{"rss_feed_bom.xml", "rss", "Feed Title", false},
 		{"rss_feed_leading_spaces.xml", "rss", "Feed Title", false},
 		{"rdf_feed.xml", "rss", "Feed Title", false},
 		{"sample.json", "json", "title", false},
@@ -109,6 +111,7 @@ func TestParser_ParseURL_Success(t *testing.T) {
 		{"atom03_feed.xml", "atom", "Feed Title", false},
 		{"atom10_feed.xml", "atom", "Feed Title", false},
 		{"rss_feed.xml", "rss", "Feed Title", false},
+		{"rss_feed_bom.xml", "rss", "Feed Title", false},
 		{"rss_feed_leading_spaces.xml", "rss", "Feed Title", false},
 		{"rdf_feed.xml", "rss", "Feed Title", false},
 		{"sample.json", "json", "title", false},
diff --git a/testdata/parser/universal/rss_feed_bom.xml b/testdata/parser/universal/rss_feed_bom.xml
new file mode 100644
index 0000000..243a189
--- /dev/null
+++ b/testdata/parser/universal/rss_feed_bom.xml
@@ -0,0 +1,8 @@
+﻿<!--
+Description: rss feed with byte order mark
+-->
+<rss version="2.0">
+  <channel>
+    <title>Feed Title</title>
+  </channel>
+</rss>