求助!!!,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

《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 5

知识盲区,帮你顶一下。

2年前 评论
西巴以及 (楼主) 2年前
$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);
2年前 评论
西巴以及 (楼主) 2年前

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