Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] Panic when non-obligatory link field is not given to item #97

Closed
Jeeejeets opened this issue Oct 20, 2022 · 5 comments
Closed

[bug] Panic when non-obligatory link field is not given to item #97

Jeeejeets opened this issue Oct 20, 2022 · 5 comments
Labels

Comments

@Jeeejeets
Copy link

Jeeejeets commented Oct 20, 2022

Describe the bug

According to RSS 2.0 spec and the site given in README https://www.rssboard.org/rss-specification#hrelementsOfLtitemgt
there is no need for link element in item. Still, if it's ommited, then the program execution results in panic.

Versions

Go version: v1.19.2
package version: v1.1.1

Steps to Reproduce

Just do everything that is done in README code, except for links in items - do not provide them. Then run feed.toRss() and the panic should occur.

Expected behavior

No panic. Or at least mention in documentation that the link is needed, although I discourage it and think it is better for package to be compatible with spec.

Code Snippets

package main

import (
	"fmt"
	"github.com/gorilla/feeds"
	"log"
	"time"
)

func main() {
	now := time.Now()
	feed := &feeds.Feed{
		Title:       "jmoiron.net blog",
		Link:        &feeds.Link{Href: "http://jmoiron.net/blog"},
		Description: "discussion about tech, footie, photos",
		Author:      &feeds.Author{Name: "Jason Moiron", Email: "jmoiron@jmoiron.net"},
		Created:     now,
	}

	feed.Items = []*feeds.Item{
		&feeds.Item{
			Title:       "Limiting Concurrency in Go",
			Description: "A discussion on controlled parallelism in golang",
			Author:      &feeds.Author{Name: "Jason Moiron", Email: "jmoiron@jmoiron.net"},
			Created:     now,
		},
		&feeds.Item{
			Title:       "Logic-less Template Redux",
			Description: "More thoughts on logicless templates",
			Created:     now,
		},
		&feeds.Item{
			Title:       "Idiomatic Code Reuse in Go",
			Description: "How to use interfaces <em>effectively</em>",
			Created:     now,
		},
	}

	rss, err := feed.ToRss()
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(rss)
}

@Jeeejeets Jeeejeets added the bug label Oct 20, 2022
@MexHigh
Copy link

MexHigh commented Nov 12, 2022

I also ran into this problem today. When adding an empty Link element, it does not panic:

if item.Link == nil {
	item.Link = &feeds.Link{}
}

However, you end up with an empty <link> tag.

But nevertheless, this error should at least be returned by feed.ToRss() and feed.ToAtom() or not be generated at all.

@amustaque97
Copy link

I agree with you @Gumkle that the link should be optional. Since there is no active development in the project you can fork the project and make the required changes. We can close this issue.

@MexHigh
Copy link

MexHigh commented Nov 13, 2022

There is already an MR for it here: #96

@amustaque97
Copy link

@Gumkle please close the issue. MR is merged

@Jeeejeets
Copy link
Author

Okay, didn't check it because I don't have time right now, but believe you it's ok. Closing issue now. Thank you for discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants