From 73e2dd73573738bfea829c7685a4a4dda6bd6a57 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sun, 5 Jan 2020 19:26:14 +0100 Subject: Handle yet another "too complex" sqlite error --- doc/changelog.asciidoc | 2 ++ qutebrowser/misc/sql.py | 4 ++-- tests/unit/completion/test_histcategory.py | 18 ++++++++++++++++-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/doc/changelog.asciidoc b/doc/changelog.asciidoc index 500ca4285..5f9d27351 100644 --- a/doc/changelog.asciidoc +++ b/doc/changelog.asciidoc @@ -109,6 +109,8 @@ Fixed - The tab hover text now shows ampersands (&) correctly. - With QtWebEngine and Qt >= 5.11, the inspector now shows its icons correctly even if loading of images is disabled via the `content.images` setting. +- Crash when entering a very long string (over 50k characters) in the + completion. - Various improvements for URL/searchengine detection: - Strings with a dot but with characters not allowed in a URL (e.g. an underscore) are now not treated as URL anymore. diff --git a/qutebrowser/misc/sql.py b/qutebrowser/misc/sql.py index 4b12d8134..39208819d 100644 --- a/qutebrowser/misc/sql.py +++ b/qutebrowser/misc/sql.py @@ -119,9 +119,9 @@ def raise_sqlite_error(msg, error): # If the query we built was too long too_long_err = ( error_code == SqliteErrorCode.ERROR and - driver_text == "Unable to execute statement" and (database_text.startswith("Expression tree is too large") or - database_text == "too many SQL variables")) + database_text in ["too many SQL variables", + "LIKE or GLOB pattern too complex"])) if error_code in known_errors or qtbug_70506 or too_long_err: raise KnownError(msg, error) diff --git a/tests/unit/completion/test_histcategory.py b/tests/unit/completion/test_histcategory.py index 9a5cd7edf..b9d20cae6 100644 --- a/tests/unit/completion/test_histcategory.py +++ b/tests/unit/completion/test_histcategory.py @@ -22,6 +22,8 @@ import datetime import logging +import hypothesis +from hypothesis import strategies import pytest from qutebrowser.misc import sql @@ -135,15 +137,27 @@ def test_set_pattern_repeated(model_validator, hist): ]) -def test_set_pattern_long(hist, message_mock, caplog): +@pytest.mark.parametrize('pattern', [ + ' '.join(map(str, range(10000))), + 'x' * 50000, +], ids=['numbers', 'characters']) +def test_set_pattern_long(hist, message_mock, caplog, pattern): hist.insert({'url': 'example.com/foo', 'title': 'title1', 'last_atime': 1}) cat = histcategory.HistoryCategory() with caplog.at_level(logging.ERROR): - cat.set_pattern(" ".join(map(str, range(10000)))) + cat.set_pattern(pattern) msg = message_mock.getmsg(usertypes.MessageLevel.error) assert msg.text.startswith("Error with SQL query:") +@hypothesis.given(pat=strategies.text()) +def test_set_pattern_hypothesis(hist, pat, caplog): + hist.insert({'url': 'example.com/foo', 'title': 'title1', 'last_atime': 1}) + cat = histcategory.HistoryCategory() + with caplog.at_level(logging.ERROR): + cat.set_pattern(pat) + + @pytest.mark.parametrize('max_items, before, after', [ (-1, [ ('a', 'a', '2017-04-16'), -- cgit v1.2.3-54-g00ecf