Firefox 和 UTF-16 编码
我正在构建一个使用 UTF-16 编码的网站。这意味着每个文件(html,jsp)都以UTF-18编码,并且我在每个HTML页面的头部设置:
<meta http-equiv="content-type" content="text/html; charset=UTF-16">
我的索引页面由Chrom和IE正确显示。但是,Firefox 不呈现索引。它显示 2 个奇怪的字符和完整的索引页代码:
��<!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-16"> ...
你知道原因吗?应该是编码的问题,但我不知道它位于哪里......
谢谢
I'm building a website with the encoding UTF-16. It means that every files (html,jsp) is encoded in UTF-18 and I set in the head of every HTML page :
<meta http-equiv="content-type" content="text/html; charset=UTF-16">
My index page is correctly displayed by Chrom and IE. However, firefox doesn't render the index. It displays 2 strange characters and the full index page code :
��<!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-16"> ...
Do you know the reason? It should be a problem of encoding, but I don't know where it's located...
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
(声明:我是负责 Firefox 中相关代码的开发人员。)
请不要。简短的规则是:
如果您在页面上包含用户提供的内容,那么使用 UTF-16 意味着您的网站很容易受到社会工程 XSS 的影响,至少在旧版浏览器中是这样。在旧版本中尝试此演示 Firefox(版本 20 或更低版本)或基于 Presto 的 Opera 版本。
为了避免该漏洞,请使用 UTF-8。
哦。 :-)
仅当所使用的编码映射时,元标记才用作内部编码声明将元标记的字节转换为与 ASCII 相同的字节。 UTF-16 的情况并非如此。
十六进制编辑器中没有完整的响应标头和原始响应正文。如上所述,一般解决方案是始终使用 UTF-8,并且永远不要在 HTTP 上使用 UTF-16。
如果您的内容采用 UTF-16 比 UTF-8 更紧凑的语言,则有两件事:
(Disclosure: I’m the developer responsible for the relevant code in Firefox.)
Please don’t. The short rules are:
If you include user-provided content on your pages, using UTF-16 means that your site is vulnerable to socially engineered XSS at least in older browsers. Try this demo in an old version of Firefox (version 20 or older) or in a Presto-based version of Opera.
To avoid the vulnerability, use UTF-8.
Uh oh. :-)
A meta tag works as an internal encoding declaration only when the encoding being used maps the bytes of the meta tag to the same bytes ASCII would. That’s not the case for UTF-16.
Not without full response headers and the original response body in a hex editor. The general solution, as noted above, is to use always UTF-8 and never to use UTF-16 over HTTP.
If your content is in a language for which UTF-16 is more compact than UTF-8, two things:
检查服务器是否发送具有正确编码的
Content-Type
标头。Check that the server sends a
Content-Type
header with the correct encoding.