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

Relative paths in RSS feed links #1952

Closed
IgorA100 opened this issue Oct 22, 2022 · 8 comments
Closed

Relative paths in RSS feed links #1952

IgorA100 opened this issue Oct 22, 2022 · 8 comments
Labels

Comments

@IgorA100
Copy link
Contributor

IgorA100 commented Oct 22, 2022

IMPORTANT

Read and tick the following checkbox after you have created the issue or place an x inside the brackets ;)

  • [v] I have read the CONTRIBUTING.md and followed the provided tips
  • [v] I accept that the issue will be closed without comment if I do not check here
  • [v] I accept that the issue will be closed without comment if I do not fill out all items in the issue template.

Explain the Problem

If there are relative links in RSS feeds, they don't work! For example, in an XML feed, an initial link like <link>/epz/order/notice/ea20/view/common-info.html</link> will result in a 404 error when the feed is shown. will link to the local site, not the RSS feed site...

Steps to Reproduce

System Information

  • News app version: 18.3.0
  • Nextcloud version: 24.0.4
  • Cron type: system cron
  • PHP version: 8.1.2
  • Database and version: Not critical
  • Browser and version: Not critical
  • OS and version: Not critical
Contents of nextcloud/data/nextcloud.log
Paste output here
Contents of Browser Error Console Read http://ggnome.com/wiki/Using_The_Browser_Error_Console if you are unsure what to put here
Paste output here
@IgorA100 IgorA100 added the bug label Oct 22, 2022
@SMillerDev
Copy link
Contributor

Do you have an example of a feed where this goes wrong?

@IgorA100
Copy link
Contributor Author

Yes, there is, but this is a Russian site, and most likely it will not be available from another country.
Here is the link: https://zakupki.gov.ru/epz/contractfz223/search/rss
I have added a screenshot.
link

@anoymouserver
Copy link
Contributor

Can confirm here: https://secluded.site/categories/technology/index.xml (in this case they are relative starting with ../)
According to the W3C Feed Validation this feed is fully valid, but there is a recommendation to not use relative URLs.
(That's why I didn't create an issue myself in the past, but simply opened the page itself.)

See also #1605

@IgorA100
Copy link
Contributor Author

Yes, it seems that the problem is known, but no one wants to solve it :(

@SMillerDev
Copy link
Contributor

Welcome to open source, if you want something there is an open invitation to fix it yourself.

@IgorA100
Copy link
Contributor Author

For myself, I solved this problem!
You need to make THREE code changes in the file \apps\news\lib\Fetcher\FeedFetcher.php

  1. Find the following lines in the protected function buildItem(:
    protected function buildItem( ItemInterface $parsedItem, ?string $body = null, bool $RTL = false, $feedAuthor = null ): Item {
    and replace with:
    protected function buildItem( ItemInterface $parsedItem, ?string $body = null, bool $RTL = false, $feedAuthor = null, $location = null ): Item {

  2. Find the following lines in the protected function buildItem(:
    $item->setUrl($itemLink);
    and replace with:
    if ((strpos($location, 'http') === 0 || strpos($location, 'magnet') === 0)){ $UrlLocation = parse_url($location); $item->setUrl($UrlLocation['scheme']."://".$UrlLocation['host'].$itemLink); } else { $item->setUrl($itemLink); }

  3. Find the following lines in the public function fetch(:
    $builtItem = $this->buildItem($item, $body, $currRTL, $feedAuthor);
    and replace with:
    $builtItem = $this->buildItem($item, $body, $currRTL, $feedAuthor, $location);

After that, absolute URLs will be entered into the database, not relative ones!

@IgorA100
Copy link
Contributor Author

I have optimized my code a bit (by changing the old one and adding one more line) in the file \apps\news\lib\Fetcher\FeedFetcher.php
All my changes are between "// +++ IgorA100" and "// --- IgorA100"
FeedFetcher.zip

@IgorA100
Copy link
Contributor Author

I close it as completed:
alexdebril/feed-io#422

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

Successfully merging a pull request may close this issue.

3 participants