nt1m / livemarks

Extension that restores RSS Feed Livemarks in Firefox.
https://addons.mozilla.org/firefox/addon/livemarks/
MIT License
231 stars 23 forks source link

Items with relative URLs cannot be displayed #202

Closed freispiel closed 4 years ago

freispiel commented 5 years ago

Add-on version: 2.2

Describe the bug There are Wordpress blogs that contain RSS feeds with only absolute-path links in them. I.e. protocol and hostname of an item are missing. This causes

[Exception... "Component returned failure code: 0x804b000a (NS_ERROR_MALFORMED_URI) [nsIIOService.newURI]" nsresult: "0x804b000a (NS_ERROR_MALFORMED_URI)" location: "JS frame :: chrome://browser/content/parent/ext-history.js :: getVisits :: line 222" data: no]

and then

Error: Invalid bookmark: {"title":"Item 1 title","type":1,"url":"/category/test/item-1/","parentGuid":"v-i_T30roDvj"}

Interestingly enough, the feed preview in Firefox is able to handle these invalid URLs properly -- but only the preview. The feed is never processed.

To Reproduce

  1. Open Livemark settings and add the following feed: https://pastebin.com/raw/v99u0LiJ
  2. Feed is added (i.e. folder is created), but feed items are never displayed.

Expected behavior The <channel> tag is containing a proper URL in <link>, and <link> of an <item> starts with a "/". Therefore, it should not be too difficult to compile a full URL before trying to store it as a bookmark.

Extra context The sample that I put on https://pastebin.com/raw/v99u0LiJ is directly taken from a Wordpress feed (minus some private content). Yes, of course I would like Wordpress not to generate invalid RSS feeds in the first place, but I cannot do anything about that: These are not my blogs, I am only reading them....

ali1234 commented 5 years ago

I think you mean relative URLs don't work?

This happens because the feed preview is aware of where the feed comes from. However the livemarks are just dumb bookmarks and have no context. I am not sure how to best fix this. Perhaps by checking during parsing of the feed, and generating absolute URLs relative to the feed location before creating the bookmark?

freispiel commented 5 years ago

I see, @ali1234, thank you. My thoughts were: Before creating the bookmark,

Does that makes sense?

Yes, I agree, the best place is probably during parsing of the feed. I had a quick look at feed-parser.js, but I'm afraid I cannot create a patch (don't understand it well enough).

ali1234 commented 5 years ago

You don't need to handle it manually, you just do Url(link, base). Livemarks already tries to do this:

https://github.com/nt1m/livemarks/blob/master/shared/livemark-store.js#L75

It isn't working with your example because the feedUrl is itself relative.

freispiel commented 5 years ago

Apologies, I'm not sure I understand:

It isn't working with your example because the feedUrl is itself relative.

In my example, there is

<channel>
    <title>Test title</title>
    <atom:link href="/category/test/feed/" rel="self" type="application/rss+xml" />
    <link>https://pastebin.com</link>

This link is absolute. Then there is

    <item>
        <title>Item 1 title</title>
        <link>/category/test/item-1/</link>

which is relative.

How is a relative URL then ending up in feedUrl? It is obviously not taken from /rss/channel/link, because if it were, then it would not break URL(feed.siteUrl, feed.feedUrl).href...

bigdiff commented 2 years ago

I see that relative links are not clickable in the preview :thinking: or more accurately point to moz-extension://38d2cb5a-1cbc-4294-bb68-1afd33fa1039/relative/path which I guess is not very useful.

steps to reproduce in firefox: