Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

accept any value for the rel attribute #16798

Open
wants to merge 1 commit into
base: 5.x
Choose a base branch
from
Open
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
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. <[email protected]>
* @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);
}
}
Loading