Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
0.10.0
-
None
-
Windows XP SP2
VC8.0SP1
Description
Load properties file fails when calling PropertyConfigurator::configure using a MBCS string which type is char * or std::string and contains multibyte characters, such as Chinese characters.
Analyse
When calling PropertyConfigurator::configure using a MBCS string which type is char * or std::string, the constructor of File will call Transcoder::decode to convert MBCS string to DBCS string. When meets the byte which is greater than or equal to 0x80, the function will call MbstowcsCharsetDecoder::decode to process the following characters. But there is an error in MbstowcsCharsetDecoder::decode when calculating the offset after calling mbsrtowcs.
size_t converted = mbsrtowcs(buf, // This function returns the number of wide characters, maybe not equal to the number of the bytes of multibyte characters
&src,
requested,
&mbstate);
if (converted == (size_t) -1) {
stat = APR_BADARG;
in.position(src - in.data());
break;
} else {
stat = append(out, buf);
in.position(in.position() + converted); // Here, the number of the bytes of multibyte characters should be added, not the number of wide characters
}
The path "D:\Temp\中文文件夹\STC\Config\Log.properties" becomes "D:\Temp\中文文件夹\STC\Config\Log.propertiesrties" after convertion.
There are 10 bytes for the 5 Chinese characters, but only 5 wide characters. Because the error above, last 5 characters repeated.
Attachments
Issue Links
- is duplicated by
-
LOGCXX-399 Non-ascii character output wrong.
- Closed
- links to