summaryrefslogtreecommitdiff
path: root/searx/preferences.py
diff options
context:
space:
mode:
authorMarkus Heiser <markus.heiser@darmarit.de>2023-05-22 12:17:57 +0200
committerMarkus Heiser <markus.heiser@darmarit.de>2023-05-22 12:38:59 +0200
commitbc647fabafa4d1ceafcfefc1bfebbfb7d2c13008 (patch)
treed9a1274972b0ea6d46d6df4b3da61db6b3cc646a /searx/preferences.py
parent73c023bbea51c76516ea51321711d0f1d5299b7b (diff)
downloadsearxng-bc647fabafa4d1ceafcfefc1bfebbfb7d2c13008.tar.gz
searxng-bc647fabafa4d1ceafcfefc1bfebbfb7d2c13008.zip
[fix] ClientPref - don't raise exception if Accept-Language is invalid
If the Accept-Language header [1] is set but empty or holds a value that is unknown to babel, an excpetion is raised:: $ curl --header 'Accept-Language: xyz' 'http://127.0.0.1:8888/search?q=foo' ... Traceback (most recent call last): File "searx/preferences.py", line 335, in from_http_request return cls(locale=pairs[0][0]) IndexError: list index out of range [1] https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language Reported by: @Eolien55 in https://github.com/searxng/searxng/issues/2434#issuecomment-1556199789 Closes: https://github.com/searxng/searxng/issues/2434 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'searx/preferences.py')
-rw-r--r--searx/preferences.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/searx/preferences.py b/searx/preferences.py
index 8552305a7..aba712652 100644
--- a/searx/preferences.py
+++ b/searx/preferences.py
@@ -331,8 +331,12 @@ class ClientPref:
except (ValueError, babel.core.UnknownLocaleError):
continue
pairs.append((locale, qvalue))
- pairs.sort(reverse=True, key=lambda x: x[1])
- return cls(locale=pairs[0][0])
+
+ locale = None
+ if pairs:
+ pairs.sort(reverse=True, key=lambda x: x[1])
+ locale = pairs[0][0]
+ return cls(locale=locale)
class Preferences: