Add a fix for RT #121622.

This is strongly inspired by the corresponding bit in moar.
Merge pull request #341 from peschwa/rt121622

Add a fix for RT #121622.