# Buggy code
def fuzzy_url(
    urlstr: str,
    cwd: str = None,
    relative: bool = False,
    do_search: bool = True,
    force_search: bool = False,
) -> QUrl:
    """Get a QUrl based on a user input which is URL or search term.

    Args:
        urlstr: URL to load as a string.
        cwd: The current working directory, or None.
        relative: Whether to resolve relative files.
        do_search: Whether to perform a search on non-URLs.
        force_search: Whether to force a search even if the content can be
                      interpreted as a URL or a path.

    Return:
        A target QUrl to a search page or the original URL.
    """
    urlstr = urlstr.strip()
    path = get_path_if_valid(urlstr, cwd=cwd, relative=relative, check_exists=True)

    if not force_search and path is not None:
        url = QUrl.fromLocalFile(path)
    elif force_search or (do_search and not is_url(urlstr)):
        # probably a search term
        log.url.debug("URL is a fuzzy search term")
        try:
            url = _get_search_url(urlstr)
        except ValueError:  # invalid search engine
            url = qurl_from_user_input(urlstr)
    else:  # probably an address
        log.url.debug("URL is a fuzzy address")
        url = qurl_from_user_input(urlstr)
    log.url.debug(
        "Converting fuzzy term {!r} to URL -> {}".format(urlstr, url.toDisplayString())
    )
    if do_search and config.val.url.auto_search != "never" and urlstr:
        qtutils.ensure_valid(url)
    else:
        ensure_valid(url)
    return url


# Traceback (qutebrowser.utils.qtutils.QtValueError)
11:33:17 DEBUG    commands   command:run:504 Calling qutebrowser.browser.commands.CommandDispatcher.paste(<qutebrowser.browser.commands.CommandDispatcher>, True, False, False, False)
11:33:17 DEBUG    misc       commands:paste:869 Primary selection contained: 'h = back
'
11:33:17 DEBUG    url        urlutils:is_url:247 Checking if 'h = back' is a URL (autosearch=naive).
11:33:17 DEBUG    url        urlutils:fuzzy_url:193 URL is a fuzzy search term
11:33:17 DEBUG    url        urlutils:_get_search_url:91 Finding search engine for 'h = back
'
11:33:17 DEBUG    url        urlutils:_parse_search_term:78 engine None, term 'h = back
'
11:33:17 DEBUG    url        urlutils:fuzzy_url:199 Converting fuzzy term h = back
to URL ->
11:33:17 ERROR    misc       crashsignal:exception_hook:211 Uncaught exception
Traceback (most recent call last):
File "/usr/lib/python3.4/site-packages/qutebrowser/app.py", line 802, in eventFilter
return handler(event)
File "/usr/lib/python3.4/site-packages/qutebrowser/app.py", line 759, in _handle_key_event
return man.eventFilter(event)
File "/usr/lib/python3.4/site-packages/qutebrowser/keyinput/modeman.py", line 317, in eventFilter
return self._eventFilter_keypress(event)
File "/usr/lib/python3.4/site-packages/qutebrowser/keyinput/modeman.py", line 169, in _eventFilter_keypress
handled = parser.handle(event)
File "/usr/lib/python3.4/site-packages/qutebrowser/keyinput/basekeyparser.py", line 305, in handle
match = self._handle_single_key(e)
File "/usr/lib/python3.4/site-packages/qutebrowser/keyinput/modeparsers.py", line 69, in _handle_single_key
match = super()._handle_single_key(e)
File "/usr/lib/python3.4/site-packages/qutebrowser/keyinput/basekeyparser.py", line 193, in _handle_single_key
self.execute(binding, self.Type.chain, count)
File "/usr/lib/python3.4/site-packages/qutebrowser/keyinput/keyparser.py", line 42, in execute
self._commandrunner.run(cmdstr, count)
File "/usr/lib/python3.4/site-packages/qutebrowser/commands/runners.py", line 221, in run
result.cmd.run(self._win_id, args)
File "/usr/lib/python3.4/site-packages/qutebrowser/commands/command.py", line 505, in run
self.handler(*posargs, **kwargs)
File "/usr/lib/python3.4/site-packages/qutebrowser/browser/commands.py", line 871, in paste
url = urlutils.fuzzy_url(text)
File "/usr/lib/python3.4/site-packages/qutebrowser/utils/urlutils.py", line 201, in fuzzy_url
qtutils.ensure_valid(url)
File "/usr/lib/python3.4/site-packages/qutebrowser/utils/qtutils.py", line 147, in ensure_valid
raise QtValueError(obj)
qutebrowser.utils.qtutils.QtValueError: PyQt5.QtCore.QUrl('') is not valid

# Fixed code
def fuzzy_url(
    urlstr: str,
    cwd: str = None,
    relative: bool = False,
    do_search: bool = True,
    force_search: bool = False,
) -> QUrl:
    """Get a QUrl based on a user input which is URL or search term.

    Args:
        urlstr: URL to load as a string.
        cwd: The current working directory, or None.
        relative: Whether to resolve relative files.
        do_search: Whether to perform a search on non-URLs.
        force_search: Whether to force a search even if the content can be
                      interpreted as a URL or a path.

    Return:
        A target QUrl to a search page or the original URL.
    """
    urlstr = urlstr.strip()
    path = get_path_if_valid(urlstr, cwd=cwd, relative=relative, check_exists=True)

    if not force_search and path is not None:
        url = QUrl.fromLocalFile(path)
    elif force_search or (do_search and not is_url(urlstr)):
        # probably a search term
        log.url.debug("URL is a fuzzy search term")
        try:
            url = _get_search_url(urlstr)
        except ValueError:  # invalid search engine
            url = qurl_from_user_input(urlstr)
    else:  # probably an address
        log.url.debug("URL is a fuzzy address")
        url = qurl_from_user_input(urlstr)
    log.url.debug(
        "Converting fuzzy term {!r} to URL -> {}".format(urlstr, url.toDisplayString())
    )
    ensure_valid(url)
    return url