SublimeText / TrailingSpaces

Highlight trailing spaces and delete them in a flash.
MIT License
896 stars 94 forks source link

Improve character encoding compatibility #115

Closed dnicolson closed 6 years ago

dnicolson commented 7 years ago

This pull request fixes issue #48.

Trailing Spaces assumes all files are UTF-8 encoded, which can lead to errors in the console. This pull request changes this behaviour, the character encoding that Sublime Text is aware of will be used instead when opening files.

If a file without a BOM is opened, Sublime Text will default to the Windows 1252 character set if it is compatible:

unable to auto detect encoding for ~/Desktop/test.txt, using fallback encoding Western (Windows 1252)

If a file containing valid Windows 1252 characters, but invalid UTF-8 bytes (for example a file containing f4 0a) the following error would appear in the console:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf4 in position 0: invalid continuation byte