Inject fix 2afcedd into master, add unit test

Turns out the same issue is still present in master, this PR moves the fix slightly adjusted into master and adds a unit test for it.