HTMLPurifier 破坏图像

发布于 2024-09-26 22:02:20 字数 369 浏览 6 评论 0原文

我试图根据 WYSIWYG(CK 编辑器)的用户输入运行 HTMLPurifier,但图像损坏。

未过滤的输入:

<img alt="laugh" src="/lib/ckeditor/plugins/smiley/images/teeth_smile.gif" title="laugh">

使用默认设置运行净化器后:

<img alt="&quot;laugh&quot;" src="%5C" title="&quot;laugh&quot;">

我尝试更改配置设置;但我的 src 从未被保留。有什么想法吗?

I'm trying to run HTMLPurifier on user input from a WYSIWYG (CK Editor) and the images are breaking.

Unfiltered Input:

<img alt="laugh" src="/lib/ckeditor/plugins/smiley/images/teeth_smile.gif" title="laugh">

After running through purifier with default settings:

<img alt=""laugh"" src="%5C" title=""laugh"">

I have tried changing the configuration settings; but I the src is never preserved. Any thoughts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

清风不识月 2024-10-03 22:02:20

我怀疑 magic_quotes 可能是一个原因..?

您还尝试过 $config->set('Core.RemoveInvalidImg',true); 吗?您使用哪个版本? (尝试旧的或新的)

I have a suspicion that magic_quotes could be a reason..?

Also did you try $config->set('Core.RemoveInvalidImg',true);. Which version are you using? (Try older or newer)

孤千羽 2024-10-03 22:02:20

有同样的问题。
这解决了它

if (get_magic_quotes_gpc()) {
function stripslashes_gpc(&$value)
{
    $value = stripslashes($value);
}
array_walk_recursive($_GET, 'stripslashes_gpc');
array_walk_recursive($_POST, 'stripslashes_gpc');
array_walk_recursive($_COOKIE, 'stripslashes_gpc');
array_walk_recursive($_REQUEST, 'stripslashes_gpc');

}

Had the same problem.
This fixed it

if (get_magic_quotes_gpc()) {
function stripslashes_gpc(&$value)
{
    $value = stripslashes($value);
}
array_walk_recursive($_GET, 'stripslashes_gpc');
array_walk_recursive($_POST, 'stripslashes_gpc');
array_walk_recursive($_COOKIE, 'stripslashes_gpc');
array_walk_recursive($_REQUEST, 'stripslashes_gpc');

}

你与昨日 2024-10-03 22:02:20

我不知道 htmlpurifier 是什么,但是在运行它之前,您拥有的 img 标签是完全合法的(除了它未关闭)。运行它后,它会双重转义,这看起来就像垃圾。 %5C 是反斜杠的 URL 代码。看起来它试图用反斜杠来逃避正斜杠,然后就窒息了。这个程序是什么?我可以推荐 HTML Tidy 吗?

I don't know what htmlpurifier is, but the img tag you have there is perfectly legitimate (except it is unclosed) before running it. After you run it, it is doubly escaping things and that just seems like garbage. %5C is the url code for a backslash. Seems like it is trying to escape the forward slash with a backslash and then it chokes. What is this program? Can I recommend HTML Tidy?

嘦怹 2024-10-03 22:02:20

回到旧帖子,我认为这个小片段可能会帮助其他人最终到达这里。

我修复了代码中的大量与转义字符有关的异常活动,方法是将这一行添加到我的 .htaccess 文件中

php_flag magic_quotes_gpc Off

来自 PHP 文档“此功能自 PHP 5.3.0 起已弃用,自 PHP 5.4.0 起已删除” http://www.php.net/manual/en/security.magicquotes.what.php

另外,这里还有其他禁用魔术引号的方法
http://www.php.net/manual/en/security.magicquotes .disabling.php

Coming back to an old post, I thought this little snippet might help others ending up here..

I fixed a multitude of unusual activity in my code to do with escaping characters by adding this line to my .htaccess file

php_flag magic_quotes_gpc Off

From PHP documentation "This feature has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 5.4.0" http://www.php.net/manual/en/security.magicquotes.what.php

Also, here are other ways to disable magic quotes
http://www.php.net/manual/en/security.magicquotes.disabling.php

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文