backport for issue #2627
Added unittest
Merge pull request #3102 from noctarius/backport-issue-2627

backport for issue #2627