Repository: searxng/searxng

Issue:
Bug: brave.news engine
**Version of SearXNG, commit number if you are using on master branch and stipulate if you forked SearXNG**
Repository: https://github.com/searxng/searxng
Branch: master
Version: 2023.9.15+140125e64
<!-- Check if these values are correct -->

**How did you install SearXNG?**
<!-- Did you install SearXNG using the official wiki or using searxng-docker
or manually by executing the searx/webapp.py file? -->
**What happened?**
<!-- A clear and concise description of what the bug is. -->

**How To Reproduce**
<!-- How can we reproduce this issue? (as minimally and as precisely as possible) -->

**Expected behavior**
<!-- A clear and concise description of what you expected to happen. -->

**Screenshots & Logs**
<!-- If applicable, add screenshots, logs to help explain your problem. -->

**Additional context**
<!-- Add any other context about the problem here. -->

**Technical report**

Error
  * Error: json.decoder.JSONDecodeError
  * Percentage: 100
  * Parameters: `('Expecting value',)`
  * File name: `searx/engines/brave.py:218`
  * Function: `response`
  * Code: `json_data = js_variable_to_python(datastr)`




Discussion:

Resolving patch:
diff --git a/searx/engines/brave.py b/searx/engines/brave.py
--- a/searx/engines/brave.py
+++ b/searx/engines/brave.py
@@ -219,8 +219,7 @@ def response(resp):
     json_resp = json_data[1]['data']['body']['response']
 
     if brave_category == 'news':
-        json_resp = json_resp['news']
-        return _parse_news(json_resp)
+        return _parse_news(json_resp['news'])
 
     if brave_category == 'images':
         return _parse_images(json_resp)
@@ -299,7 +298,7 @@ def _parse_news(json_resp):
             'title': result['title'],
             'content': result['description'],
         }
-        if result['thumbnail'] != "null":
+        if result['thumbnail'] is not None:
             item['img_src'] = result['thumbnail']['src']
         result_list.append(item)
 
@@ -339,7 +338,7 @@ def _parse_videos(json_resp):
             'duration': result['video']['duration'],
         }
 
-        if result['thumbnail'] != "null":
+        if result['thumbnail'] is not None:
             item['thumbnail'] = result['thumbnail']['src']
 
         iframe_src = _get_iframe_src(url)
diff --git a/searx/utils.py b/searx/utils.py
--- a/searx/utils.py
+++ b/searx/utils.py
@@ -40,6 +40,7 @@
 
 _JS_QUOTE_KEYS_RE = re.compile(r'([\{\s,])(\w+)(:)')
 _JS_VOID_RE = re.compile(r'void\s+[0-9]+|void\s*\([0-9]+\)')
+_JS_DECIMAL_RE = re.compile(r":\s*\.")
 
 _STORAGE_UNIT_VALUE: Dict[str, int] = {
     'TB': 1024 * 1024 * 1024 * 1024,
@@ -699,7 +700,7 @@ def js_variable_to_python(js_variable):
             # replace simple quote by double quote
             parts[i] = '"'
             in_string = None
-        #
+
         if not in_string:
             # replace void 0 by null
             # https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/void
@@ -714,6 +715,7 @@ def js_variable_to_python(js_variable):
     # becomes
     # { "a": 12 }
     s = _JS_QUOTE_KEYS_RE.sub(r'\1"\2"\3', s)
+    s = _JS_DECIMAL_RE.sub(":0.", s)
     # replace the surogate character by colon
     s = s.replace(chr(1), ':')
     # load the JSON and return the result


Test patch: