Fixes #12637: Merged fix from 3.2 and added test.