Ensure output encoding matches input encoding