Fix crashes on invalid URLs