Added a test for trac ticket 4471, and fixed the issue.