1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-22 05:39:43 +00:00

Merge branch 'l10n_validate' into 'master'

Validate l10n context name

See merge request OpenMW/openmw!1910
This commit is contained in:
jvoisin 2022-05-23 20:19:55 +00:00
commit 7df5e7f62a

View file

@ -122,6 +122,16 @@ namespace LuaUtil
auto it = mContexts.find(contextName);
if (it != mContexts.end())
return sol::make_object(mLua->sol(), it->second);
auto allowedChar = [](char c)
{
return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') ||
(c >= '0' && c <= '9') || c == '_';
};
bool valid = !contextName.empty();
for (char c : contextName)
valid = valid && allowedChar(c);
if (!valid)
throw std::runtime_error(std::string("Invalid l10n context name: ") + contextName);
icu::Locale fallbackLocale(fallbackLocaleName.c_str());
Context ctx{contextName, std::make_shared<l10n::MessageBundles>(mPreferredLocales, fallbackLocale)};
{