Skip to content

Commit

Permalink
accept any value for the rel attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
i-just committed Feb 28, 2025
1 parent d92d67b commit f4fb387
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/helpers/HtmlPurifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace craft\helpers;

use craft\htmlpurifier\RelAttrLinkTypeDef;
use craft\htmlpurifier\VideoEmbedUrlDef;
use HTMLPurifier_Config;
use HTMLPurifier_Encoder;
Expand Down Expand Up @@ -83,6 +84,8 @@ public static function configure($config): void

$def->addElement('oembed', 'Block', 'Inline', 'Common');
$def->addAttribute('oembed', 'url', new VideoEmbedUrlDef());

$def->addAttribute('a', 'rel', new RelAttrLinkTypeDef('rel'));
}
}
}
30 changes: 30 additions & 0 deletions src/htmlpurifier/RelAttrLinkTypeDef.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* @link https://craftcms.com/
* @copyright Copyright (c) Pixel & Tonic, Inc.
* @license https://craftcms.github.io/license/
*/

namespace craft\htmlpurifier;

use HTMLPurifier_AttrDef_HTML_LinkTypes;

/**
* Class VideoEmbedUrlDef
*
* @author Pixel & Tonic, Inc. <support@pixelandtonic.com>
* @since 5.6.11
*/
class RelAttrLinkTypeDef extends HTMLPurifier_AttrDef_HTML_LinkTypes
{
public function validate($string, $config, $context)
{
// allow any value in the "rel" attribute
$allowed = $config->get('Attr.' . $this->name);
if (isset($allowed['*']) && $allowed['*']) {
return $string;
}

return parent::validate($string, $config, $context);
}
}

0 comments on commit f4fb387

Please # to comment.