diff options
author | Florian Bruhin <me@the-compiler.org> | 2020-11-25 18:58:33 +0100 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2020-11-25 18:58:33 +0100 |
commit | 9e1ab361729a3ccad8ce2d0afb2d5c4230eddeb4 (patch) | |
tree | 3444e12457f542cb7ce0ca9319ce93e25dadaa89 | |
parent | ff96894f18ba5b7d6c5d2f3282d63599c9709b52 (diff) | |
download | qutebrowser-9e1ab361729a3ccad8ce2d0afb2d5c4230eddeb4.tar.gz qutebrowser-9e1ab361729a3ccad8ce2d0afb2d5c4230eddeb4.zip |
Make sure all Qt regexes are valid
-rw-r--r-- | qutebrowser/completion/models/listcategory.py | 1 | ||||
-rw-r--r-- | tests/unit/completion/test_completiondelegate.py | 9 | ||||
-rw-r--r-- | tests/unit/completion/test_models.py | 12 |
3 files changed, 21 insertions, 1 deletions
diff --git a/qutebrowser/completion/models/listcategory.py b/qutebrowser/completion/models/listcategory.py index f0cc21da0..79dc0770a 100644 --- a/qutebrowser/completion/models/listcategory.py +++ b/qutebrowser/completion/models/listcategory.py @@ -64,6 +64,7 @@ class ListCategory(QSortFilterProxyModel): val = re.escape(val) val = val.replace(r'\ ', '.*') rx = QRegExp(val, Qt.CaseInsensitive) + qtutils.ensure_valid(rx) self.setFilterRegExp(rx) self.invalidate() sortcol = 0 diff --git a/tests/unit/completion/test_completiondelegate.py b/tests/unit/completion/test_completiondelegate.py index 41dfee98b..4732837a1 100644 --- a/tests/unit/completion/test_completiondelegate.py +++ b/tests/unit/completion/test_completiondelegate.py @@ -18,6 +18,8 @@ # along with qutebrowser. If not, see <http://www.gnu.org/licenses/>. from unittest import mock +import hypothesis +import hypothesis.strategies import pytest from PyQt5.QtCore import Qt from PyQt5.QtGui import QTextDocument, QColor @@ -69,6 +71,13 @@ def test_benchmark_highlight(benchmark): benchmark(bench) +@hypothesis.given(text=hypothesis.strategies.text()) +def test_pattern_hypothesis(text): + """Make sure we can't produce invalid patterns.""" + doc = QTextDocument() + completiondelegate._Highlighter(doc, text, Qt.red) + + def test_highlighted(qtbot): """Make sure highlighting works. diff --git a/tests/unit/completion/test_models.py b/tests/unit/completion/test_models.py index 2ac7084dd..8b4653b58 100644 --- a/tests/unit/completion/test_models.py +++ b/tests/unit/completion/test_models.py @@ -26,6 +26,8 @@ import time from datetime import datetime from unittest import mock +import hypothesis +import hypothesis.strategies import pytest from PyQt5.QtCore import QUrl, QDateTime try: @@ -37,7 +39,8 @@ except ImportError: from qutebrowser.misc import objects from qutebrowser.completion import completer -from qutebrowser.completion.models import miscmodels, urlmodel, configmodel +from qutebrowser.completion.models import ( + miscmodels, urlmodel, configmodel, listcategory) from qutebrowser.config import configdata, configtypes from qutebrowser.utils import usertypes from qutebrowser.mainwindow import tabbedbrowser @@ -1324,3 +1327,10 @@ def test_undo_completion(tabbed_browser_stubs, info): "2020-01-01 00:00"), ], }) + + +@hypothesis.given(text=hypothesis.strategies.text()) +def test_listcategory_hypothesis(text): + """Make sure we can't produce invalid patterns.""" + cat = listcategory.ListCategory("test", []) + cat.set_pattern(text) |