求助!!!,HTMLPurifier 配置 video标签加白,但无法生效,依然过滤了html中的video标签。

运行环境

PHP 版本:PHP8.0
Web 框架:Hyperf
系统环境:Docker容器

HTMLPurifier 代码配置

$original = "";
$config = \HTMLPurifier_Config::createDefault();
$config->set('Core.Encoding', 'UTF-8');
$config->set('HTML.Doctype', 'HTML 4.01 Transitional');
$config->set('HTML.DefinitionRev', 1);
$config->set('HTML.Allowed', 'video,source,div,b,strong,i,em,a[href|title],ul,ol,ol[start],li,p[style],br,span[style],img[width|height|alt|src],*[style|class],pre,hr,code,h2,h3,h4,h5,h6,blockquote,del,table,thead,tbody,tr,th,td');
$config->set('CSS.AllowedProperties', config('purifier.css_allowed'));
$config->set('AutoFormat.AutoParagraph', true);
$config->set('AutoFormat.RemoveEmpty', true);
$config->set('Cache.DefinitionImpl', null);

$clearHtml = $config->purify($content);

执行之后控制台出现警告:

HTMLPurifier 配置 video标签加白,但无法生效,依然过滤了html中的video标签。

提供的字符串:

$original = <div><video class='class' src="https://videocmc.kunmingbc.com/kmgbdst/vod/2023/05/09/5333e7ba3be942a9af49f0286761535f/5333e7ba3be942a9af49f0286761535f_h264_1200k_mp4.mp4" controls="controls"></video></div>

输出的结果:

echo $clearHtml;
输出结果:""

您实际得到的结果?

得到video标签,以及video标签里边的内容包含src controls source

《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
讨论数量: 5

知识盲区,帮你顶一下。

10个月前 评论
西巴以及 (楼主) 10个月前
$def = $htmlPurifierConfig->getHTMLDefinition(true);
$def->addElement(   // add video tag
    'video',   // name
    'Block',  // content set
    'Flow', // allowed children
    'Common', // attribute collection
    array( // attributes
        'src' => 'URI',
        'width' => 'Length',
        'height' => 'Length',
        'style' => 'CDATA'
    )
);

$purifier = new HTMLPurifier($htmlPurifierConfig);
10个月前 评论
西巴以及 (楼主) 10个月前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!