In laravel 8 app with mews/purifier: 3.4,
I need to show youtube video(defined using <iframe …)
As youtube iframe block is cleared by Purifier::clean( method I found branch
Laravel Package Purifer not work with iframe
and tried to modify my config/purifier.php file like:
'settings' => [
'default' => [
'HTML.Doctype' => 'HTML 4.01 Transitional',
// I added this iframe rule
'HTML.Allowed' => 'iframe[src|width|height|class|frameborder],h1,h2,h3,div,blockquote,table,tbody,tr,td,figure,b,strong,i,em,u,a[href|title],ul,ol,li,p[style],br,span[style],img[width|height|alt|src]',
'CSS.AllowedProperties' => 'font,font-size,font-weight,font-style,font-family,text-decoration,padding-left,color,background-color,text-align',
'AutoFormat.AutoParagraph' => false,
'AutoFormat.RemoveEmpty' => true,
],
'test' => [
'Attr.EnableID' => 'true',
],
'youtube' => [
"HTML.SafeIframe" => 'true',
"Filter.YouTube" => 'true',
// I suppose this rule means all iframes are allowed
"URI.SafeIframeRegexp" => '%.+%',
],
But I got error :
Element 'iframe' is not supported (for information on implementing this, see the support forums)
(View: /mnt/_work_sdb8/wwwroot/lar/HRBrazy/affiliate/resources/views/news/show.blade.php)
How that can be fixed ?
2
Answers
The configuration looks right for HTML Purifier. This script does what it should:
This gives me:
If I comment out the lines that are in your
'youtube'
configuration block, however, like so:…then I get your error:
Unfortunately, I don’t know anything about the Laravel integration here, and how you choose which configuration is active, but if you make sure that the
'youtube'
and'default'
blocks are actually being combined and used, that should solve your problem.Just add ‘youtube’ at last as config, it works for me in laravel 10:
clean($request->body, 'youtube');