fix issue #879 and add a test for it