Fixed (#841)

This is a fix for #841 and supporting test.
No, I just left the comment above - you can go ahead and fix the PR. Bonus point if you can do a little git gymnastics and amend the first (red) PR, keeping the second (green) PR as it is :wink: