douan2907 2015-07-23 03:01
浏览 103

调用HTMLPurifier-> getHTMLDefinition()正在改变HTMLPurifier的行为

I'm using HTMLPurifier to sanitize some HTML I'm getting from a form. However when I call getHTMLDefinition() on my config it causes HTMLPurifier->purify() to throw a warning.

Here's my setup:

$HPConfig = HTMLPurifier_Config::createDefault();
$HPConfig->set('Cache.SerializerPath', APPLICATION_ROOT.'/forums/cache/HtmlPurifier');
$HPConfig->set('HTML.Doctype', 'XHTML 1.0 Transitional');
$HPConfig->set('HTML.AllowedElements', ['p','br','img','i','b']);
$HPConfig->set('HTML.AllowedAttributes', ['href','style']);
$HPConfig->set('CSS.AllowedProperties', 'text-align');

$HPConfig->set('HTML.DefinitionID', 'myapp-text.html');
$HPConfig->set('HTML.DefinitionRev', 2);
$def = $HPConfig->getHTMLDefinition(true);

$HtmlPurifier = new HTMLPurifier($HPConfig); 
$text = $HtmlPurifier->purify($text);

When I use the above code my script throws this warning:

Warning: Global attribute 'href' is not supported in any elements (for information on implementing this, see the support forums)  in /var/...

However, if I simply remove the $def = $HPConfig->getHTMLDefinition(true); line the warning disappears. What does the getHTMLDefinition() method do that causes HTMLPurifier's behaviour to change? and is there a way to prevent it from happening?

  • 写回答

1条回答 默认 最新

  • dscpg80066 2015-07-23 20:02
    关注

    Well, the warning is right: href isn't supported for all elements, so you have to say a.href to allow href on a tags.

    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP