This fixes a problem with X-chat (and possibly others). (upstream git commit 8a3574f301725ba48484c05408e35ecec27aad65)