Fix issue #3738
Add test cases for issue #3738
Add other two test cases
Merge pull request #1989 from lidavidm/issue_3738

Fix issue 3738