mmcdole / gofeed

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

Parsing atom feeds without `xml:base` does not resolve relative links #155

Closed nkanaev closed 4 years ago

nkanaev commented 4 years ago

Expected behavior

Absolute link in ParseURL.

Actual behavior

Relative links are provided as is.

Steps to reproduce the behavior

script to test:

package main

import (
    "fmt"
    "github.com/mmcdole/gofeed"
)

func main() {
    parser := gofeed.NewParser()
    feed, _ := parser.ParseURL("https://bou.ke/feed.xml")
    fmt.Println(feed.Link)      // outputs "/"
    fmt.Println(feed.FeedLink)  // outputs "/feed.xml"
}

partial file content:

<feed xmlns="http://www.w3.org/2005/Atom">
    <generator uri="https://jekyllrb.com/" version="4.0.1">Jekyll</generator>
    <link href="/feed.xml" rel="self" type="application/atom+xml"/>
    <link href="/" rel="alternate" type="text/html"/>
    <updated>2020-07-13T09:26:52+00:00</updated>
...

Full feed is provided here: bouke.xml

Notes

Given that such links have to be handled manually in Parse, ParseString methods anyways, I'd like to hear opinions on whether it's worth implementing the fix, or should be the library users' responsibility.