Resolve relative URLs (assuming URI.Base==notice URL)

The real way to do this would be to get the xml:base property from
the Atom feed but it's probably not there in any posts we see today.
This commit is contained in:
Mikael Nordfeldth 2016-02-26 14:46:26 +01:00
parent 1e6520fddd
commit 52a3764ae4
2 changed files with 7 additions and 3 deletions

View File

@ -854,8 +854,8 @@ class Notice extends Managed_DataObject
if (mb_strlen($content)===0 && !is_null($actobj)) {
$content = mb_strlen($actobj->content) ? $actobj->content : $actobj->summary;
}
// Strip out any bad HTML from $content
$stored->rendered = common_purify($content);
// Strip out any bad HTML from $content. URI.Base is used to sort out relative URLs.
$stored->rendered = common_purify($content, ['URI.Base' => $stored->url ?: null]);
$stored->content = common_strip_html($stored->getRendered(), true, true);
if (trim($stored->content) === '') {
// TRANS: Error message when the plain text content of a notice has zero length.

View File

@ -580,7 +580,7 @@ function common_canonical_email($email)
return $email;
}
function common_purify($html)
function common_purify($html, array $args=array())
{
require_once INSTALLDIR.'/extlib/HTMLPurifier/HTMLPurifier.auto.php';
@ -588,6 +588,10 @@ function common_purify($html)
$cfg->set('Attr.AllowedRel', ['bookmark', 'directory', 'enclosure', 'home', 'license', 'nofollow', 'payment', 'tag']); // http://microformats.org/wiki/rel
$cfg->set('HTML.ForbiddenAttributes', array('style')); // id, on* etc. are already filtered by default
$cfg->set('URI.AllowedSchemes', array_fill_keys(common_url_schemes(), true));
if (isset($args['URI.Base'])) {
$cfg->set('URI.Base', $args['URI.Base']); // if null this is like unsetting it I presume
$cfg->set('URI.MakeAbsolute', !is_null($args['URI.Base'])); // if we have a URI base, convert relative URLs to absolute ones.
}
// Remove more elements than what the default filter removes, default in GNU social are remotely
// linked resources such as img, video, audio