diff --git a/composer.json b/composer.json index 5157e0f3ed..f1460b9f44 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,6 @@ "christophwurst/kitinerary-sys": "^0.1.0", "ezyang/htmlpurifier": "4.13.0", "gravatarphp/gravatar": "^2.0", - "kwi/urllinker": "dev-bleeding", "pear-pear.horde.org/horde_date": "^2.4.1@stable", "pear-pear.horde.org/horde_exception": "^2.0.8@stable", "pear-pear.horde.org/horde_imap_client": "^2.29.16@stable", @@ -43,7 +42,8 @@ "pear-pear.horde.org/horde_text_flowed": "^2.0.3@stable", "pear-pear.horde.org/horde_util": "^2.5.8@stable", "psr/log": "^1", - "rubix/ml": "0.4.0" + "rubix/ml": "0.4.0", + "youthweb/urllinker": "^1.3" }, "require-dev": { "christophwurst/nextcloud": "v20.0.7", diff --git a/composer.lock b/composer.lock index acb8ca4640..952e1641c7 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "13a7f364726053a06bffc79501d9eb33", + "content-hash": "5dde7d9dc7c0a14d5bdf73fa8a896f1c", "packages": [ { "name": "amphp/amp", @@ -834,61 +834,6 @@ ], "time": "2019-01-08T21:43:01+00:00" }, - { - "name": "kwi/urllinker", - "version": "dev-bleeding", - "source": { - "type": "git", - "url": "https://github.com/kwi-dk/UrlLinker.git", - "reference": "bc54f1afe6ef25752b46ace3931f7d157e7342f0" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/kwi-dk/UrlLinker/zipball/bc54f1afe6ef25752b46ace3931f7d157e7342f0", - "reference": "bc54f1afe6ef25752b46ace3931f7d157e7342f0", - "shasum": "" - }, - "require": { - "php": ">=5.3" - }, - "type": "library", - "autoload": { - "psr-4": { - "Kwi\\": "lib" - }, - "files": [ - "UrlLinker.php" - ] - }, - "autoload-dev": { - "files": [ - "tests/UrlLinkerTestCase.php", - "tests/functions/LinkUrlsInTrustedHtmlTest.php", - "tests/functions/HtmlEscapeAndLinkUrlsTest.php" - ] - }, - "license": [ - "CC0-1.0" - ], - "authors": [ - { - "name": "Søren Løvborg", - "role": "Developer" - }, - { - "name": "Dawid Nowak", - "email": "code@dnowak.pl", - "role": "Developer" - } - ], - "description": "Autolink URLs in text or html", - "homepage": "http://www.kwi.dk/projects/php/UrlLinker/", - "support": { - "source": "https://bitbucket.org/kwi/urllinker", - "issues": "https://bitbucket.org/kwi/urllinker/issues" - }, - "time": "2014-12-28T22:05:00+00:00" - }, { "name": "league/flysystem", "version": "2.0.4", @@ -2211,6 +2156,51 @@ } ], "time": "2021-01-07T16:49:33+00:00" + }, + { + "name": "youthweb/urllinker", + "version": "1.3.0", + "source": { + "type": "git", + "url": "https://github.com/youthweb/urllinker.git", + "reference": "b583abc45d70fee67104798bb73193de34cee5df" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/youthweb/urllinker/zipball/b583abc45d70fee67104798bb73193de34cee5df", + "reference": "b583abc45d70fee67104798bb73193de34cee5df", + "shasum": "" + }, + "require": { + "php": "^7.2" + }, + "require-dev": { + "phpunit/phpunit": "^6 || ^7 || ^8" + }, + "type": "library", + "autoload": { + "psr-4": { + "Youthweb\\UrlLinker\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-3.0-or-later" + ], + "authors": [ + { + "name": "Søren Løvborg", + "role": "Developer" + }, + { + "name": "Dawid Nowak", + "email": "code@dnowak.pl", + "role": "Developer" + } + ], + "description": "Autolink URLs in text or html", + "homepage": "https://github.com/youthweb", + "time": "2019-10-01T12:10:40+00:00" } ], "packages-dev": [ @@ -2613,7 +2603,6 @@ "aliases": [], "minimum-stability": "stable", "stability-flags": { - "kwi/urllinker": 20, "pear-pear.horde.org/horde_date": 0, "pear-pear.horde.org/horde_exception": 0, "pear-pear.horde.org/horde_imap_client": 0, diff --git a/lib/Service/Html.php b/lib/Service/Html.php index 29e32e628d..7983b35d32 100755 --- a/lib/Service/Html.php +++ b/lib/Service/Html.php @@ -33,7 +33,6 @@ use HTMLPurifier_HTMLDefinition; use HTMLPurifier_URIDefinition; use HTMLPurifier_URISchemeRegistry; -use Kwi\UrlLinker; use OCA\Mail\Service\HtmlPurify\CidURIScheme; use OCA\Mail\Service\HtmlPurify\TransformCSSBackground; use OCA\Mail\Service\HtmlPurify\TransformHTMLLinks; @@ -43,6 +42,7 @@ use OCP\IRequest; use OCP\IURLGenerator; use OCP\Util; +use Youthweb\UrlLinker\UrlLinker; require_once __DIR__ . '/../../vendor/cerdic/css-tidy/class.csstidy.php'; @@ -64,7 +64,10 @@ public function __construct(IURLGenerator $urlGenerator, IRequest $request) { * @return string */ public function convertLinks(string $data): string { - $linker = new UrlLinker(true, false); + $linker = new UrlLinker([ + 'allowFtpAddresses' => true, + 'allowUpperCaseUrlSchemes' => false, + ]); $data = $linker->linkUrlsAndEscapeHtml($data); $config = HTMLPurifier_Config::createDefault(); diff --git a/tests/Unit/Service/HtmlTest.php b/tests/Unit/Service/HtmlTest.php index ed3b4ae6bb..778068d3c3 100644 --- a/tests/Unit/Service/HtmlTest.php +++ b/tests/Unit/Service/HtmlTest.php @@ -1,5 +1,7 @@ * @author Thomas Müller @@ -25,6 +27,8 @@ use ChristophWurst\Nextcloud\Testing\TestCase; use OC; use OCA\Mail\Service\Html; +use OCP\IRequest; +use OCP\IURLGenerator; class HtmlTest extends TestCase { @@ -33,19 +37,21 @@ class HtmlTest extends TestCase { * @param $expected * @param $text */ - public function testLinkDetection($expected, $text) { - $urlGenerator = OC::$server->getURLGenerator(); - $request = OC::$server->getRequest(); + public function testLinkDetection(string $expected, string $text) { + $urlGenerator = OC::$server->get(IURLGenerator::class); + $request = OC::$server->get(IRequest::class); + $html = new Html($urlGenerator, $request); $withLinks = $html->convertLinks($text); - $this->assertSame($expected, $withLinks); + + self::assertSame($expected, $withLinks); } public function linkDetectionProvider() { return [ ['abc', 'abc'], ['<>', '<>'], - ['&lt;&gt;', '<>'], + ['<>', '<>'], // no double encoding ['foo&bar', 'foo&bar'], ['google.com', 'http://google.com'], ['google.com', 'https://google.com'], diff --git a/vendor-bin/cs-fixer/composer.json b/vendor-bin/cs-fixer/composer.json index f2f6c5f039..f5e516d3d3 100644 --- a/vendor-bin/cs-fixer/composer.json +++ b/vendor-bin/cs-fixer/composer.json @@ -1,6 +1,6 @@ { "require-dev": { - "friendsofphp/php-cs-fixer": "^2.18", + "friendsofphp/php-cs-fixer": "2.18.3", "nextcloud/coding-standard": "^0.5.0" } } diff --git a/vendor-bin/cs-fixer/composer.lock b/vendor-bin/cs-fixer/composer.lock index 9a8e70575a..70a528f1d2 100644 --- a/vendor-bin/cs-fixer/composer.lock +++ b/vendor-bin/cs-fixer/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "a6e3788adce81b2d1a96833b4bdc5c4b", + "content-hash": "5a42ac4f837c38a435abf0b493f0a051", "packages": [], "packages-dev": [ {