fixes #6334 Encoding not correct when importing data

Fixed the issue and pushed the code for review, please check it.