Basically this is not a good case when an empty string is passed ...
Alternatively, you can just remove the "if not" check altogether ...