diff options
-rw-r--r-- | db/item.php | 4 | ||||
-rw-r--r-- | fetcher/feedfetcher.php | 6 | ||||
-rw-r--r-- | tests/unit/articleenhancer/XPathArticleEnhancerTest.php | 4 | ||||
-rw-r--r-- | tests/unit/db/ItemTest.php | 14 | ||||
-rw-r--r-- | tests/unit/fetcher/FeedFetcherTest.php | 2 |
5 files changed, 20 insertions, 10 deletions
diff --git a/db/item.php b/db/item.php index 5c0472eaf..70d3cbb07 100644 --- a/db/item.php +++ b/db/item.php @@ -176,5 +176,9 @@ class Item extends Entity implements IAPI { } + public function setBody($body) { + parent::setBody(str_replace('<a', '<a target="_blank"', $body)); + } + } diff --git a/fetcher/feedfetcher.php b/fetcher/feedfetcher.php index fdc062d6c..705404518 100644 --- a/fetcher/feedfetcher.php +++ b/fetcher/feedfetcher.php @@ -138,10 +138,8 @@ class FeedFetcher implements IFeedFetcher { // links should always open in a new window $item->setBody( - str_replace( - '<a', '<a target="_blank"', $this->purifier->purify( - $simplePieItem->get_content() - ) + $this->purifier->purify( + $simplePieItem->get_content() ) ); diff --git a/tests/unit/articleenhancer/XPathArticleEnhancerTest.php b/tests/unit/articleenhancer/XPathArticleEnhancerTest.php index a0f8db388..26381057c 100644 --- a/tests/unit/articleenhancer/XPathArticleEnhancerTest.php +++ b/tests/unit/articleenhancer/XPathArticleEnhancerTest.php @@ -229,7 +229,7 @@ class XPathArticleEnhancerTest extends \OCA\AppFramework\Utility\TestUtility { ->will($this->returnValue('<a href="https://www.explosm.net/a/relative/url.html?a=1#b">link</a><a href="https://www.explosm.net/all/b/relative/url.html">link2</a><img src="https://www.explosm.net/another/relative/link.jpg">')); $result = $this->testEnhancer->enhance($item); - $this->assertEquals('<a href="https://www.explosm.net/a/relative/url.html?a=1#b">link</a><a href="https://www.explosm.net/all/b/relative/url.html">link2</a><img src="https://www.explosm.net/another/relative/link.jpg">', $result->getBody()); + $this->assertEquals('<a target="_blank" href="https://www.explosm.net/a/relative/url.html?a=1#b">link</a><a target="_blank" href="https://www.explosm.net/all/b/relative/url.html">link2</a><img src="https://www.explosm.net/another/relative/link.jpg">', $result->getBody()); } public function testTransformRelativeUrlSpecials() { @@ -282,7 +282,7 @@ class XPathArticleEnhancerTest extends \OCA\AppFramework\Utility\TestUtility { ->will($this->returnValue('<img src="http://www.url.com/absolute/url.png"><a href="mailto:test@testsite.com">mail</a>')); $result = $this->testEnhancer->enhance($item); - $this->assertEquals('<img src="http://www.url.com/absolute/url.png"><a href="mailto:test@testsite.com">mail</a>', $result->getBody()); + $this->assertEquals('<img src="http://www.url.com/absolute/url.png"><a target="_blank" href="mailto:test@testsite.com">mail</a>', $result->getBody()); } }
\ No newline at end of file diff --git a/tests/unit/db/ItemTest.php b/tests/unit/db/ItemTest.php index b4360f273..dab4fdd90 100644 --- a/tests/unit/db/ItemTest.php +++ b/tests/unit/db/ItemTest.php @@ -200,9 +200,17 @@ class ItemTest extends \PHPUnit_Framework_TestCase { public function testSetGuidUpdatesHash() { - $feed = new Item(); - $feed->setGuid('http://test'); - $this->assertEquals(md5('http://test'), $feed->getGuidHash()); + $item = new Item(); + $item->setGuid('http://test'); + $this->assertEquals(md5('http://test'), $item->getGuidHash()); + } + + + public function testMakeLinksInBodyOpenNewTab() { + $item = new Item(); + $item->setBody("<a href=\"test\">ha</a>"); + $this->assertEquals("<a target=\"_blank\" href=\"test\">ha</a>", + $item->getBody()); } diff --git a/tests/unit/fetcher/FeedFetcherTest.php b/tests/unit/fetcher/FeedFetcherTest.php index 466bcc446..83ba3b809 100644 --- a/tests/unit/fetcher/FeedFetcherTest.php +++ b/tests/unit/fetcher/FeedFetcherTest.php @@ -199,7 +199,7 @@ class FeedFetcherTest extends \OCA\AppFramework\Utility\TestUtility { $item->setTitle('my<\' title'); $item->setGuid($this->guid); $item->setGuidHash(md5($this->guid)); - $item->setBody($this->body2); + $item->setBody($this->body); $item->setLastModified($this->time); if($author) { $mock = $this->getMock('author', array('get_name')); |