mirror of
https://github.com/miniflux/v2.git
synced 2024-09-05 19:09:21 +02:00
Every once in a while, one of my feeds would throw an XML parse error because it used ` ` or some other HTML entity. I feel Miniflux should be lenient here, and Go already has a handy hook to make this work.
30 lines
749 B
Go
30 lines
749 B
Go
// Copyright 2017 Frédéric Guillot. All rights reserved.
|
|
// Use of this source code is governed by the Apache 2.0
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package rss // import "miniflux.app/reader/rss"
|
|
|
|
import (
|
|
"encoding/xml"
|
|
"io"
|
|
|
|
"miniflux.app/errors"
|
|
"miniflux.app/model"
|
|
"miniflux.app/reader/encoding"
|
|
)
|
|
|
|
// Parse returns a normalized feed struct from a RSS feed.
|
|
func Parse(data io.Reader) (*model.Feed, *errors.LocalizedError) {
|
|
feed := new(rssFeed)
|
|
decoder := xml.NewDecoder(data)
|
|
decoder.Entity = xml.HTMLEntity
|
|
decoder.CharsetReader = encoding.CharsetReader
|
|
|
|
err := decoder.Decode(feed)
|
|
if err != nil {
|
|
return nil, errors.NewLocalizedError("Unable to parse RSS feed: %q", err)
|
|
}
|
|
|
|
return feed.Transform(), nil
|
|
}
|