1
0
mirror of https://github.com/searxng/searxng.git synced 2024-11-20 11:20:10 +01:00

Merge pull request #1664 from return42/harden-get_engine_locales

[fix] harden get_engine_locale: handle UnknownLocaleError exceptions
This commit is contained in:
Markus Heiser 2022-08-14 14:25:14 +02:00 committed by GitHub
commit 649d1a144d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -213,7 +213,13 @@ def get_engine_locale(searxng_locale, engine_locales, default=None):
# need to narrow language nor territory.
return engine_locale
try:
locale = babel.Locale.parse(searxng_locale, sep='-')
except babel.core.UnknownLocaleError:
try:
locale = babel.Locale.parse(searxng_locale.split('-')[1])
except babel.core.UnknownLocaleError:
return default
# SearXNG's selected locale is not supported by the engine ..