diff options
author | Florian Bruhin <me@the-compiler.org> | 2021-07-13 16:23:40 +0200 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2021-07-28 13:17:59 +0200 |
commit | cb478162e5b3057eb3f0661adb6b2a0ee080f6ee (patch) | |
tree | f5a0d6aa2b4281817e7fc37a2fd12ae1f9c077a5 | |
parent | d95b0435d872b92359d9c4c95a1a590b56bee54e (diff) | |
download | qutebrowser-cb478162e5b3057eb3f0661adb6b2a0ee080f6ee.tar.gz qutebrowser-cb478162e5b3057eb3f0661adb6b2a0ee080f6ee.zip |
Handle and test more file path corner cases
(cherry picked from commit 676c9db2fe9833e52b12f723c3ed62a38759f82d)
-rw-r--r-- | qutebrowser/completion/models/filepathcategory.py | 4 | ||||
-rw-r--r-- | tests/unit/completion/test_models.py | 9 |
2 files changed, 9 insertions, 4 deletions
diff --git a/qutebrowser/completion/models/filepathcategory.py b/qutebrowser/completion/models/filepathcategory.py index f9b6608a3..db2733b4f 100644 --- a/qutebrowser/completion/models/filepathcategory.py +++ b/qutebrowser/completion/models/filepathcategory.py @@ -93,9 +93,9 @@ class FilePathCategory(QAbstractListModel): else: try: expanded = os.path.expanduser(val) - except UnicodeEncodeError: + except (UnicodeEncodeError, ValueError): # os.path.expanduser('~\ud800') can raise UnicodeEncodeError - # via pwd.getpwnam + # via pwd.getpwnam. '~\x00' can raise ValueError. expanded = val paths = self._glob(expanded) self._paths = sorted(self._contract_user(val, path) for path in paths) diff --git a/tests/unit/completion/test_models.py b/tests/unit/completion/test_models.py index 45506fe6a..c20fe293c 100644 --- a/tests/unit/completion/test_models.py +++ b/tests/unit/completion/test_models.py @@ -462,8 +462,7 @@ def test_filesystem_completion_model_interface(info, local_files_path): @hypothesis.given( as_uri=hst.booleans(), add_sep=hst.booleans(), - text=hst.text(alphabet=hst.characters( - blacklist_categories=['Cc'], blacklist_characters='\x00')), + text=hst.text(), ) def test_filesystem_completion_hypothesis(info, as_uri, add_sep, text): if as_uri: @@ -475,6 +474,12 @@ def test_filesystem_completion_hypothesis(info, as_uri, add_sep, text): model.set_pattern(text) +@pytest.mark.parametrize('text', ['~\ud800', '~\x00']) +def test_filesystem_completion_corner_cases(info, text): + model = filepathcategory.FilePathCategory('filepaths') + model.set_pattern(text) + + def test_default_filesystem_completion(qtmodeltester, config_stub, info, web_history_populated, quickmarks, bookmarks, local_files_path): |