From bdfb9c60ccc21df278b4ee450e50d7627b367186 Mon Sep 17 00:00:00 2001 From: Christopher Pezley Date: Sat, 21 Oct 2017 21:01:07 +0200 Subject: [PATCH] Fix issue where opening a file whose name contains characters not present in locale would cause a crash. Fixes qutebrowser/qutebrowser/1450 --- qutebrowser/utils/urlutils.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/qutebrowser/utils/urlutils.py b/qutebrowser/utils/urlutils.py index 709d7d732..dff1ef8f1 100644 --- a/qutebrowser/utils/urlutils.py +++ b/qutebrowser/utils/urlutils.py @@ -372,8 +372,14 @@ def get_path_if_valid(pathstr, cwd=None, relative=False, check_exists=False): path = None if check_exists: - if path is not None and os.path.exists(path): - log.url.debug("URL is a local file") + if path is not None: + # If the path contains characters that the locale cannot handle, + # then we consider it as non-existent. + try: + if os.path.exists(path): + log.url.debug("URL is a local file") + except UnicodeEncodeError: + path = None else: path = None