Skip to content

fix: resolve ../ and ./ relative links in feed item HTML content - #95

Merged
Grotax merged 1 commit into
mainfrom
copilot/check-relative-link-resolution
Jul 19, 2026
Merged

Grotax merged 1 commit into
mainfrom
copilot/check-relative-link-resolution

Conversation

Copilot AI commented Jul 3, 2026

Copy link
Copy Markdown

Node::setHostInContent() left ../ and ./ relative paths unresolved in item HTML content. Feeds like https://wiki.xxiivv.com/links/log.xml embed relative links (href='../site/page.html', src='../media/image.png') in <description> CDATA, which were passed through unchanged.

Changes

  • src/FeedIo/Feed/Node.php — adds private resolveRelativePathLinksInContent(string $itemFullLink), called from setHostInContent() between the #fragment and bare-word handlers. Uses preg_replace_callback with a backreference-aware pattern to match both '- and "-quoted ..//./ attributes, then normalizes each path via a stack-based resolver (RFC 3986–style) against the item's base directory:
// href='../media/refs/hello.png' with item link https://wiki.xxiivv.com/site/2026.html
// → href='https://wiki.xxiivv.com/media/refs/hello.png'
$pattern = '~((?:href|src)=)(["\'])(\.{1,2}/[^"\'<>\s]*)\2~i';
  • tests/FeedIo/Feed/NodeTest.php — adds three tests: ../ resolution, ./ resolution, and no-op on already-absolute URLs.
  • tests/samples/rss/sample-rss-relative-links.xml — minimal RSS fixture modelled on the xxiivv feed structure.

@Grotax

Grotax commented Jul 3, 2026

Copy link
Copy Markdown

Resolves: nextcloud/news#3822

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes feed item HTML rewriting so ../ and ./ relative href/src links embedded in item content/description are resolved into absolute URLs based on the item’s full link, improving correctness for feeds that embed relative paths in CDATA.

Changes:

  • Add relative-path (../ / ./) URL resolution step to Node::setHostInContent() via a new private helper.
  • Add PHPUnit coverage for ../, ./, and “already absolute” cases.
  • Add an RSS fixture containing relative links and document the fix in the changelog.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/FeedIo/Feed/Node.php Adds logic to resolve ../ / ./ links in content/description to absolute URLs.
tests/FeedIo/Feed/NodeTest.php Adds tests validating relative-path resolution and no-op behavior for absolute URLs.
tests/samples/rss/sample-rss-relative-links.xml Adds an RSS sample fixture with relative href/src values in CDATA.
CHANGELOG.md Records the fix under Unreleased.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/FeedIo/Feed/Node.php
Comment thread src/FeedIo/Feed/Node.php Outdated
Comment thread tests/FeedIo/Feed/NodeTest.php
Add resolveRelativePathLinksInContent() private method to Node that
handles href/src attributes starting with ../ or ./. These paths are
normalized against the item's base directory using stack-based path
resolution, then replaced with absolute URLs.

Previously, Node::setHostInContent() only handled:
- /absolute/path hrefs
- #fragment hrefs
- word-starting relative hrefs (e.g. page.html)

Relative paths with dot segments (../path, ./path) were left unresolved,
breaking links in feeds like https://wiki.xxiivv.com/links/log.xml whose
<description> elements contain HTML with ../media/ and ../site/ hrefs.

Also add tests and a sample RSS fixture with relative ../  links.
@Grotax
Grotax force-pushed the copilot/check-relative-link-resolution branch from 2b6c706 to 0131fcb Compare July 19, 2026 09:28
@Grotax
Grotax marked this pull request as ready for review July 19, 2026 09:28
@Grotax
Grotax merged commit 2c5300f into main Jul 19, 2026
8 checks passed
@Grotax
Grotax deleted the copilot/check-relative-link-resolution branch July 19, 2026 09:29
@Grotax Grotax mentioned this pull request Jul 19, 2026
Grotax added a commit that referenced this pull request Jul 19, 2026
Fixed
- fix: ensure magnet links remain unchanged when setting host in content (#102)
- fix: resolve `../` and `./` relative links in feed item HTML content (#95)
Grotax added a commit that referenced this pull request Jul 19, 2026
Fixed
- fix: ensure magnet links remain unchanged when setting host in content (#102)
- fix: resolve `../` and `./` relative links in feed item HTML content (#95)
@Grotax Grotax added the enhancement New feature or request label Jul 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants