mmcdole / gofeed

Parse RSS, Atom and JSON feeds in Go
MIT License
2.51k stars 204 forks source link

Undetect Json array #188

Closed StayPirate closed 2 years ago

StayPirate commented 2 years ago

Expected behavior

If I try to parse a Json file starting with a [ I want it to be parsed.

Actual behavior

It doesn't parse this feed or the same one with only one element.

Steps to reproduce the behavior

I get the following error error parsing https://chromiumdash.appspot.com/fetch_releases?channel=Stable&platform=Linux contents: Failed to detect feed type

Note: Please include any links to problem feeds, or the feed content itself!

I think this is due to the following lines: https://github.com/mmcdole/gofeed/blob/68ee9054d97bf13a4ac38f802d2e9c1bcff2991d/detector.go#L74-L78

Maybe something like: (?)

 } else if firstChar == '{' or if firstChar == '[' { 
    // Check if document is valid JSON 
    if jsoniter.Valid(buffer.Bytes()) { 
        return FeedTypeJSON 
    } 
StayPirate commented 2 years ago

I did some test on my own, and it doesn't seem to be that easy. I think I misunderstood what a Json feed is.... It should be something with a fixed structure, and not any random Json file, am I correct? Something like the following example, which I took from jsonfeed.org

{
    "version": "https://jsonfeed.org/version/1.1",
    "title": "My Example Feed",
    "home_page_url": "https://example.org/",
    "feed_url": "https://example.org/feed.json",
    "items": [
        {
            "id": "2",
            "content_text": "This is a second item.",
            "url": "https://example.org/second-item"
        },
        {
            "id": "1",
            "content_html": "<p>Hello, world!</p>",
            "url": "https://example.org/initial-post"
        }
    ]
}

While I was trying to pass this Json file.

StayPirate commented 2 years ago

for my use-case, monitoring when a new version of Chrome is released for Linux, probably urlwatch would be a better fit.