remove bom

This commit is contained in:
Nazar Kanaev 2021-04-07 10:25:30 +01:00
parent 42b36965c5
commit fbb0dfed47
3 changed files with 17 additions and 0 deletions

View File

@ -152,6 +152,7 @@ The parser should be reasonably handle content provided by them.
Delete any from the list in case they drop support of web feeds.
- blogger
- cnblogs
- flickr
- hatenablog
- livejournal

View File

@ -17,6 +17,7 @@ type processor func(r io.Reader) (*Feed, error)
func sniff(lookup string) (string, processor) {
lookup = strings.TrimSpace(lookup)
lookup = strings.TrimLeft(lookup, "\x00\xEF\xBB\xBF\xFE\xFF")
switch lookup[0] {
case '<':
decoder := xmlDecoder(strings.NewReader(lookup))

View File

@ -92,3 +92,18 @@ func TestParseShortFeed(t *testing.T) {
t.FailNow()
}
}
func TestParseFeedWithBOM(t *testing.T) {
have, err := Parse(strings.NewReader(
"\xEF\xBB\xBF" + `<?xml version="1.0"?><feed xmlns="http://www.w3.org/2005/Atom"></feed>`,
))
want := &Feed{}
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(want, have) {
t.Logf("want: %#v", want)
t.Logf("have: %#v", have)
t.FailNow()
}
}