Fix issue #1724

This PR fix the issue #1724.
I've written a test to prove that now is actually working. I don't know if the test is good or you prefer to do it in some other way. I'm happy to change it, trash it or whatever :)