Regression test and fix for  #3898