Revert 893daf4 and add test for issue 8642

fixes #8642
Merge pull request #8644 from skirpichev/8642-fix

Revert 893daf4 and add test for issue 8642