NetTopologySuite / NetTopologySuite.IO.ShapeFile

The ShapeFile IO module for NTS.
33 stars 25 forks source link

Whitespaces in cpg file prevents to detect correct encoding. #38

Closed Alexey-Stolyarov closed 1 month ago

Alexey-Stolyarov commented 4 years ago

In this line you're trying to use content of cpg file as is. But whitespaces, line endings, etc prevents to detect correct encoding. https://github.com/NetTopologySuite/NetTopologySuite.IO.ShapeFile/blob/bef5ec80cc5b1b5a95f4df3bfc5a61ab837525a1/src/NetTopologySuite.IO.ShapeFile/Dbase/DbaseFileHeader.cs#L511

E.g. these lines will lead to ArgumentException which will lead to default encoding instead of desirable.

Encoding.GetEncoding("UTF-8/r/n")
Encoding.GetEncoding("UTF-8 ")

Suggestion - trim leading and trailing whitespaces.

KubaSzostak commented 1 month ago

Support for a different encodings has been added in the successor library. There is also a sample code demonstrating how to custom encoding.