Fix handling of invalid empty URLs

fixes #2399