fix #1396 and add a test for it