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
locale = babel.Locale.parse(searxng_locale, sep='-')
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 ..