Fixed #60858, which showed a regression of the fix for #56420 introduced by my refactoring to fix #56822. Includes new unit test based on the bug sample file.