简体   繁体   English

如何阻止 htmlPurifier 自动解码 html 实体?

[英]How do I stop htmlPurifier from automatically decoding html entities?

I have a strange issue.我有一个奇怪的问题。 I use CKEditor-4 to collect formatted text from user in form of html.我使用 CKEditor-4 以 html 的形式从用户那里收集格式化文本。 Also, the html content is filtered using htmlpurifier from the server.此外,使用来自服务器的 htmlpurifier 过滤 html 内容。

When the user use quotes like , ' and CKEditor converts them into html entities like ”当用户使用像' CKEditor这样的引号时,将它们转换为html实体,如” , ’ , ’ , and “ , 和“ , which is fine. ,这很好。 The issue is, when I filter them using htmlpurifier - this quotes get's automatically decoded.问题是,当我使用 htmlpurifier 过滤它们时 - 这个引号会自动解码。 This prevents the content from: being presented to user for later edit as the quotes are literally encoded in strage ways like “这可以防止内容: 呈现给用户以供以后编辑,因为引号按字面意思以“ “ ”之类的方式编码

How do i fix this?我该如何解决? I think, if I could stop htmlpurifier from automatically decoding things, this would work, But I am new to htmlpurifier - so I can't find a way.我认为,如果我可以阻止 htmlpurifier 自动解码,这将起作用,但我是 htmlpurifier 的新手 - 所以我找不到方法。

I have tried using htmlentities before passing it to htmlpurifier.在将其传递给 htmlpurifier 之前,我曾尝试使用htmlentities but it would encode the whole html, Hence: stopping htmlpurifier from purifying html at all.但它会编码整个 html,因此:完全停止 htmlpurifier 净化 html。

After CBroe's comment, I found out that my application is not using UTF-8 all the way through.在 CBroe 的评论之后,我发现我的应用程序并没有一直使用 UTF-8。

And I can't rectify it also.我也无法纠正它。 For those who are in similar situation, I found a work-around.对于那些处于类似情况的人,我找到了解决方法。 htmlPurifier does support a configuration to encode all non-ASCII charecters with some trade-offs - It's fine with my case(I think). htmlPurifier 确实支持对所有非 ASCII 字符进行编码的配置,但需要进行一些权衡 - 我的情况很好(我认为)。

you can enable the htmlpurifier config Core.EscapeNonASCIICharacters like so您可以像这样启用 htmlpurifier 配置Core.EscapeNonASCIICharacters

$config->set('Core.EscapeNonASCIICharacters', true);

which did the trick for me.这对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM