对表单中的用户输入强制执行正确的 UTF-8 编码
我有一个用 asp.net 编写的 Web 表单,允许用户输入内容,然后将其保存到数据库并写为 xml 文件,供第三方导入到他们的系统中。
我们将 xml 文件输出为 UTF-8。
他们目前遇到一个问题,欧元符号 (€) 破坏了他们的 xml 解析器,并出现以下错误:
解析器错误:输入不是正确的 UTF-8,指示编码!
From 符号对我来说看起来没问题,但显然,当用户将其复制到我的表单中时,用户可以从任何源复制该符号,因此它可能不是 UTF-8 编码的。
我的问题:
1.) 我如何 100% 知道欧元符号是否是 UTF-8 编码的?有没有什么编辑器可以让我以 UTF-8 格式查看它?
2.) 有没有办法可以在输入或粘贴到表单中时检查字符,以确保将其保存为 UTF-8 编码?
谢谢大家的建议!
埃德
i have a web form written in asp.net that allows user enter content which is then saved to a DB and written out as an xml file for a third party to import into their systems.
We output the xml file as UTF-8.
They currently have a problem where a euro symbol (€) is breaking their xml parser with the following error:
parser error : Input is not proper UTF-8, indicate encoding !
From symbol looks ok to me but obviously as the user could be copying this symbol from any source when they copy it into my form it might not be UTF-8 encoded.
My questions:
1.) How do I know 100% if the euro symbol is UTF-8 encoded or not? Is there some editor where I can view it as UTF-8?
2.) Is there a way I can check a character when it is entered or pasted into the form to ensure it is saved as UTF-8 encoded?
Thanks everyone for your advice!
Ed
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您正在获取 Web 表单提交的数据并将其按原样放入 XML 中,而无需先对其进行验证。这不是一个好主意。在使用数据之前务必验证您的数据。另外,请确保 Web 表单本身具有“charset=utf-8”属性,以便兼容的浏览器能够以 UTF-8 格式将数据传输到服务器。
It sounds like you are taking the webform's submitted data and putting it in the XML as-is without validating it first. That is not a good idea. Alwyas validate your data before using it. Also, make sure the webform itself has a "charset=utf-8" attribute on it so that compliant browsers will transmit the data to the server in UTF-8.