Comment 23 for bug 1251590

Here's the patch,

tests pass - but we need more tests for this - I was working on adding them today but didn't manage.

We can post a fix and add tests later too actually.