Fix redmine #2810

And sanitize some ugly output while doing that.