Thanks.  First, would it be possible to add tests for these
situations?

I added a test case in the attached updated patch. I wasn't able to test it though. Please make sure it works as expected.
 
And second, your contributions (this and the other one) are larger
than we can accept without your assigning the copyright to the FSF.
Would you like to start your legal paperwork at this time, so that we
could accept the changes after it is completed?  If so, I will send
you the form to fill.

Sure