Skip to content

Commit

Permalink
Disallow creating variables with invalid WML tag names (fixes #3877)
Browse files Browse the repository at this point in the history
Variables are saved as WML elements, and as such, variable names must also
be valid WML tag names.
  • Loading branch information
jyrkive committed Jan 18, 2019
1 parent e57ecf4 commit e0aa686
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/variable_info_detail.hpp
Expand Up @@ -41,6 +41,11 @@ class vi_policy_const
static const config& get_child_at(const config& cfg, const std::string& key, int index)
{
assert(index >= 0);

if(!config::valid_tag(key)) {
throw invalid_variablename_exception();
}

// cfg.child_or_empty does not support index parameter
if(const config& child = cfg.child(key, index)) {
return child;
Expand All @@ -63,6 +68,11 @@ class vi_policy_create
static config& get_child_at(config& cfg, const std::string& key, int index)
{
assert(index >= 0);

if (!config::valid_tag(key)) {
throw invalid_variablename_exception();
}

// the 'create_if_not_existent' logic.
while(static_cast<int>(cfg.child_count(key)) <= index) {
cfg.add_child(key);
Expand Down

0 comments on commit e0aa686

Please sign in to comment.