mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-27 03:40:24 +00:00
Validate l10n context name
This commit is contained in:
parent
14aec3791c
commit
a4b23aad05
1 changed files with 10 additions and 0 deletions
|
@ -122,6 +122,16 @@ namespace LuaUtil
|
||||||
auto it = mContexts.find(contextName);
|
auto it = mContexts.find(contextName);
|
||||||
if (it != mContexts.end())
|
if (it != mContexts.end())
|
||||||
return sol::make_object(mLua->sol(), it->second);
|
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());
|
icu::Locale fallbackLocale(fallbackLocaleName.c_str());
|
||||||
Context ctx{contextName, std::make_shared<l10n::MessageBundles>(mPreferredLocales, fallbackLocale)};
|
Context ctx{contextName, std::make_shared<l10n::MessageBundles>(mPreferredLocales, fallbackLocale)};
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue