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: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
103 changes: 46 additions & 57 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions lib/Service/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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';

Expand All @@ -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();
Expand Down
16 changes: 11 additions & 5 deletions tests/Unit/Service/HtmlTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Thomas Müller <thomas.mueller@tmit.eu>
Expand All @@ -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 {

Expand All @@ -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;', '<>'],
['&amp;lt;&amp;gt;', '&lt;&gt;'],
['&lt;&gt;', '&lt;&gt;'], // no double encoding
['foo&amp;bar', 'foo&bar'],
['<a href="http://google.com" rel="noreferrer noopener" target="_blank">google.com</a>', 'http://google.com'],
['<a href="https://google.com" rel="noreferrer noopener" target="_blank">google.com</a>', 'https://google.com'],
Expand Down
2 changes: 1 addition & 1 deletion vendor-bin/cs-fixer/composer.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
2 changes: 1 addition & 1 deletion vendor-bin/cs-fixer/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.