0

I'm using resx files to store localized content for some web apps. I've been asked to write a test mechanism to know if those resource files have non UTF-8 content on the values.

The resx files are XML files that on their header specify that they are UTF-8 encoded. So my question (maybe obvious or silly) is, can somebody add non UTF-8 strings into the resource file values?

I've already searched how to get the encoding for some string, but there is not bullet proof method, so I'm not sure if that test that I've been asked to create is either needed or possible...

EDIT Just for clarification, the test should be performed within the localized app, and if the string is not a valid UTF-8 then display a default (localized) value

4

1 回答 1

0

在某种程度上,是的。您可以毫无困难地存储纯 ASCII 文本。

在那之外?你最好的办法是为它写一个测试。在代码中定义一些非 UTF8 字符串,将它们存储在 .resx 文件中(ResxRescourceWriter为简单起见),然后将它们拉回。将它们打印到屏幕上,看看它们是否匹配。

当然也可以更改 resx 文件的编码。如果这样做,则可以存储以该格式编码的字符串。

你最好的选择是尝试看看会发生什么。

编辑:基于评论中的澄清。

如果您需要验证现有值,最好的办法是遍历 resx 文件,将所有文本转储到 .txt 文件中。

如果您随后在 Notepad++ 中打开该文件,则可以指定 UTF-8 编码。任何无法以可读方式显示的内容都不是 UTF-8 文本,并且在从 resx 中拉出时将无法正确显示。

于 2013-04-09T21:00:20.993 回答