laravelhtmlpurifier

Why Element 'iframe' is not supported for youtube links with mews/purifier?


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 ?


Solution

  • Just add 'youtube' at last as config, it works for me in laravel 10:
    clean($request->body, 'youtube');