SearXNG is a free internet metasearch engine which aggregates results from various search services and databases. Users are neither tracked nor profiled.
Python bingbravedegoogleduckduckgogooglemetasearchprivacypythonqwantsearchsearch-enginesearxsearxngstartpageyahoo
[fix] engines: wikidata, no list as content when an entity has no description (#6824)
Guillaume P.6671d89bede8
diff --git a/searx/engines/wikidata.py b/searx/engines/wikidata.pyindex 5662dc6db..32a7c0b67 100644--- a/searx/engines/wikidata.py+++ b/searx/engines/wikidata.py@@ -167,7 +167,7 @@ def get_results(infobox_id_lang: str | None = Noneinfobox_urls: list[dict[str, str]] = []infobox_attributes: list[dict[str, str]] = []- infobox_content = attribute_result.get("itemDescription", [])+ infobox_content: str = attribute_result.get("itemDescription", "")img_src: str | None = Noneimg_src_priority = 0diff --git a/tests/unit/test_engine_wikidata.py b/tests/unit/test_engine_wikidata.pynew file mode 100644index 000000000..bb1b37505--- /dev/null+++ b/tests/unit/test_engine_wikidata.py@@ -0,0 +1,27 @@+# SPDX-License-Identifier: AGPL-3.0-or-later+# pylint: disable=missing-module-docstring,disable=missing-class-docstring++from unittest.mock import patch++from searx.engines import wikidata+from searx.wikidata_properties import get_attributes+from tests import SearxTestCase+++class WikidataGetResultsTests(SearxTestCase):++ ITEM = "http://www.wikidata.org/entity/Q1"++ def test_no_desc_list(self):+ # an entity without "itemDescription" must not leak a list into "content"+ attribute_result = {"item": self.ITEM, "itemLabel": "Label"}+ with patch.object(wikidata, "display_type", ["list"]):+ results = wikidata.get_results(attribute_result, get_attributes("en"), "en")+ self.assertEqual(results, [{"url": self.ITEM, "title": "Label", "content": ""}])++ def test_no_desc_infobox(self):+ attribute_result = {"item": self.ITEM, "itemLabel": "Label"}+ with patch.object(wikidata, "display_type", ["infobox"]):+ results = wikidata.get_results(attribute_result, get_attributes("en"), "en")+ self.assertEqual(len(results), 1)+ self.assertEqual(results[0]["content"], "")