NetTopologySuite.IO.ShapeFile icon indicating copy to clipboard operation
NetTopologySuite.IO.ShapeFile copied to clipboard

Chinese character transcoding error

Open DeliciousExtra opened this issue 4 years ago • 8 comments

In DbaseFileHeader class line 311 string name = DbaseEncodingUtility.Latin1.GetString(buffer, 0, buffer.Length); when the field value is Chinese character, it cant get the correct value. it should be use the Detected encoding from line 294 var encoding = DetectEncoding(ldid, cpgStreamProvider); to encoding the value, string name = encoding.GetString(buffer, 0, buffer.Length); then it get the correct value

DeliciousExtra avatar Jun 18 '20 02:06 DeliciousExtra

In DbaseFileHeader class line 311 string name = DbaseEncodingUtility.Latin1.GetString(buffer, 0, buffer.Length); when the field value is Chinese character, it cant get the correct value. it should be use the Detected encoding from line 294 var encoding = DetectEncoding(ldid, cpgStreamProvider); to encoding the value, string name = encoding.GetString(buffer, 0, buffer.Length); then it get the correct value

for (int i = 0; i < length; i++)
{
    keys[i] = reader.DbaseHeader.Fields[i].Name;
    keys[i] = Encoding.GetEncoding("GBK").GetString(reader.DbaseHeader.Encoding.GetBytes(keys[i]));
}

it works well in temporary.

axmand avatar Nov 06 '20 01:11 axmand

can you post a complete unit test or at least a complete unit of code that we can use to build a unit test using chinese characters? Thanks

DGuidi avatar Nov 06 '20 06:11 DGuidi

ok I see that probably there's some problem here

in L310

// NOTE: only this _encoding.GetString method is available in Silverlight
string name = DbaseEncodingUtility.Latin1.GetString(buffer, 0, buffer.Length);

but in L294

var encoding = DetectEncoding(ldid, cpgStreamProvider);
if (_encoding == null) _encoding = encoding;

so I suppose the correct code for L310 might be

// NOTE: Silverlight is gone, baby... forgot and move on
string name = _encoding.GetString(buffer, 0, buffer.Length);

DGuidi avatar Nov 06 '20 08:11 DGuidi

@FObermaier just take a look also here, please :)

DGuidi avatar Nov 06 '20 09:11 DGuidi

@FObermaier @airbreather how about this fix? i can easily push this change if there is any objection

DGuidi avatar Nov 18 '20 06:11 DGuidi

@DGuidi LGTM :heavy_check_mark:

edit: just please make sure there's a test for it

airbreather avatar Nov 18 '20 11:11 airbreather

@axmand please can you provide at least some test data so I can build a valid test for this issue?

DGuidi avatar Nov 18 '20 12:11 DGuidi

please check if last commit fix the issue, as expected

DGuidi avatar Nov 23 '20 07:11 DGuidi