Test cases for #784

I can confirm: your change works for me. I've added test cases for this scenario.