Avoid an IndexError when dealing with empty strings

Fixes #778
Merge pull request #779 from he7d3r/patch-1

Avoid an IndexError when dealing with empty strings