Thanks for the bug report and test case. I installed the attached patch, which fixed the bug for me, and which adds a similar test case to the test database.