Test case and fix for #1381