Regression test and fix for  #3898

Fixes #3898