public function testAllowingUpperCaseSchemes() { $urlLinker = new UrlLinker(false, true); $text = '<div>HTTP://example.com</div>'; $expectedText = '<div><a href="HTTP://example.com">example.com</a></div>'; $this->assertSame($expectedText, $urlLinker->linkUrlsAndEscapeHtml($text)); $html = '<div>HTTP://example.com</div>'; $expectedHtml = '<div><a href="HTTP://example.com">example.com</a></div>'; $this->assertSame($expectedHtml, $urlLinker->linkUrlsInTrustedHtml($html)); }
/** * @param string $data * @return string */ public function convertLinks($data) { $linker = new UrlLinker(true, false); $data = $linker->linkUrlsInTrustedHtml($data); $config = HTMLPurifier_Config::createDefault(); // Append target="_blank" to all link (a) elements $config->set('HTML.TargetBlank', true); // allow cid, http and ftp $config->set('URI.AllowedSchemes', ['http' => true, 'https' => true, 'ftp' => true, 'mailto' => true]); // Disable the cache since ownCloud has no really appcache // TODO: Fix this - requires https://github.com/owncloud/core/issues/10767 to be fixed $config->set('Cache.DefinitionImpl', null); /** @var HTMLPurifier_HTMLDefinition $uri */ $uri = $config->getDefinition('HTML'); $uri->info_attr_transform_post['noreferrer'] = new TransformNoReferrer(); $purifier = new HTMLPurifier($config); return $purifier->purify($data); }
/** * @param string $text */ protected function linkify($text) { return $this->urlLinker->linkUrlsInTrustedHtml($text); }