FLEX-34543 Accepting patch from Marcus Wilkinson.
FLEX-34543 Added a unit test which reproduces the bug and thus prevents it from recurring.