Fix 'auto' encoding detection mode to make it more robust.