diff options
author | Markus Heiser <markus.heiser@darmarit.de> | 2022-01-12 18:08:48 +0100 |
---|---|---|
committer | Markus Heiser <markus.heiser@darmarit.de> | 2022-01-12 19:37:13 +0100 |
commit | 7cdd31440e621937550072c3f73e68f644554842 (patch) | |
tree | 621fbc3794b25a8de5803bfe350f662cf9b99f4b /tests/unit | |
parent | 6d7e86eece852a525ac2ec3c191aca57712ac1a7 (diff) | |
download | searxng-7cdd31440e621937550072c3f73e68f644554842.tar.gz searxng-7cdd31440e621937550072c3f73e68f644554842.zip |
[fix] external bangs: don't overwrite Bangs in data trie
Bangs with a `*` suffix (e.g. `!!d*`) overwrite Bangs with the same
prefix (e.g. `!!d`) [1]. This can be avoid when a non printable character is
used to tag a LEAF_KEY.
[1] https://github.com/searxng/searxng/pull/740#issuecomment-1010411888
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'tests/unit')
-rw-r--r-- | tests/unit/test_external_bangs.py | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/tests/unit/test_external_bangs.py b/tests/unit/test_external_bangs.py index 698ce36c6..794edf159 100644 --- a/tests/unit/test_external_bangs.py +++ b/tests/unit/test_external_bangs.py @@ -1,4 +1,10 @@ -from searx.external_bang import get_node, resolve_bang_definition, get_bang_url, get_bang_definition_and_autocomplete +from searx.external_bang import ( + get_node, + resolve_bang_definition, + get_bang_url, + get_bang_definition_and_autocomplete, + LEAF_KEY, +) from searx.search import SearchQuery, EngineRef from tests import SearxTestCase @@ -7,12 +13,12 @@ TEST_DB = { 'trie': { 'exam': { 'ple': '//example.com/' + chr(2) + chr(1) + '0', - '*': '//wikipedia.org/wiki/' + chr(2) + chr(1) + '0', + LEAF_KEY: '//wikipedia.org/wiki/' + chr(2) + chr(1) + '0', }, 'sea': { - '*': 'sea' + chr(2) + chr(1) + '0', + LEAF_KEY: 'sea' + chr(2) + chr(1) + '0', 'rch': { - '*': 'search' + chr(2) + chr(1) + '0', + LEAF_KEY: 'search' + chr(2) + chr(1) + '0', 'ing': 'searching' + chr(2) + chr(1) + '0', }, 's': { @@ -31,7 +37,7 @@ class TestGetNode(SearxTestCase): 'trie': { 'exam': { 'ple': 'test', - '*': 'not used', + LEAF_KEY: 'not used', } } } @@ -71,7 +77,7 @@ class TestResolveBangDefinition(SearxTestCase): class TestGetBangDefinitionAndAutocomplete(SearxTestCase): def test_found(self): bang_definition, new_autocomplete = get_bang_definition_and_autocomplete('exam', external_bangs_db=TEST_DB) - self.assertEqual(bang_definition, TEST_DB['trie']['exam']['*']) + self.assertEqual(bang_definition, TEST_DB['trie']['exam'][LEAF_KEY]) self.assertEqual(new_autocomplete, ['example']) def test_found_optimized(self): @@ -86,7 +92,7 @@ class TestGetBangDefinitionAndAutocomplete(SearxTestCase): def test_partial2(self): bang_definition, new_autocomplete = get_bang_definition_and_autocomplete('sea', external_bangs_db=TEST_DB) - self.assertEqual(bang_definition, TEST_DB['trie']['sea']['*']) + self.assertEqual(bang_definition, TEST_DB['trie']['sea'][LEAF_KEY]) self.assertEqual(new_autocomplete, ['search', 'searching', 'seascapes', 'season']) def test_error(self): |