Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion bin/feedio
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ function read(FeedIo $feedIo, string $url)

$items = array_reverse(iterator_to_array($feed));
foreach( $items as $i => $item ) {
echo "\033[32m{$item->getLastModified()->format(\DateTime::ATOM)} - \033[34m{$item->getTitle()}\033[0m:" . PHP_EOL;
$title = trim(preg_replace('/\s+/', ' ', $item->getTitle()));
echo "\033[32m{$item->getLastModified()->format(\DateTime::ATOM)}\033[0m - \033[34m{$title}\033[0m" . PHP_EOL;
echo "\033[36m{$item->getLink()}\033[0m" . PHP_EOL;
echo "\t". strip_tags(nl2br($item->getContent())) . PHP_EOL;
}

Expand Down
2 changes: 1 addition & 1 deletion src/FeedIo/Rule/Atom/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected function selectAlternateLink(NodeInterface $node, \DOMElement $element
($element->hasAttribute('rel') && $element->getAttribute('rel') == 'alternate')
|| is_null($node->getLink())
) {
$href = $element->getAttribute('href');
$href = trim($element->getAttribute('href'));
if (parse_url($href, PHP_URL_HOST) == null) {
$baseUrl = $node->getHostFromLink();
if ($baseUrl !== null) {
Expand Down
2 changes: 1 addition & 1 deletion src/FeedIo/Rule/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Link extends RuleAbstract
*/
public function setProperty(NodeInterface $node, \DOMElement $element): void
{
$nodeValue = $element->nodeValue;
$nodeValue = trim($element->nodeValue);
if (parse_url($nodeValue, PHP_URL_HOST) == null) {
$nodeValue = $node->getHostFromLink(). $nodeValue;
}
Expand Down
26 changes: 26 additions & 0 deletions tests/FeedIo/Rule/LinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,30 @@ public function testCreateElement()

$this->assertXmlStringEqualsXmlString('<feed><link>' . self::LINK .'</link></feed>', $document->saveXML());
}

public function testSetWithWhitespace()
{
$item = new Item();
// No initial link needed since we're testing absolute URLs with whitespace

// Test URL with leading/trailing whitespace (like in RSS feeds)
$urlWithWhitespace = "\nhttps://www.somedomain.de/test-article/view/news/123456";
$expectedUrl = 'https://www.somedomain.de/test-article/view/news/123456';

$this->object->setProperty($item, new \DOMElement('link', $urlWithWhitespace));
$this->assertEquals($expectedUrl, $item->getLink());
}

public function testSetWithRelativeUrl()
{
$item = new Item();
$item->setLink('https://example.com/base');

// Test relative URL should still work correctly
$relativeUrl = '/test-path';
$expectedUrl = 'https://example.com/test-path';

$this->object->setProperty($item, new \DOMElement('link', $relativeUrl));
$this->assertEquals($expectedUrl, $item->getLink());
}
}