I've attached a small patch which just fixes a few appendStringInfo* callsthat are not quite doing things the way that it was intended.
Regards
David Rowley