A workaround for the bug described in #684 was made in e080d33e31 but this fix is significantly cleaner. Unit test was added.
e080d33e31