diff options
| author | 2010-03-23 09:50:49 -0500 | |
|---|---|---|
| committer | 2010-08-03 17:32:41 -0400 | |
| commit | 55a095e9249cb6a87f5d6f7e50572ef3ad46dcff (patch) | |
| tree | 46332cd88eec26993c7589d42c20ad0a23430c4b /src/configparser.cpp | |
| parent | Squash a few warnings (diff) | |
Fail config parse if duplicate keys are found
Diffstat (limited to 'src/configparser.cpp')
| -rw-r--r-- | src/configparser.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/configparser.cpp b/src/configparser.cpp index 3b4b743ab..e23da82f9 100644 --- a/src/configparser.cpp +++ b/src/configparser.cpp @@ -84,7 +84,7 @@ struct Parser unget(ch); } - bool kv(std::vector<KeyVal>* items) + bool kv(std::vector<KeyVal>* items, std::set<std::string>& seen) { std::string key; nextword(key); @@ -149,6 +149,10 @@ struct Parser else value.push_back(ch); } + + if (!seen.insert(key).second) + throw CoreException("Duplicate key '" + key + "' found"); + items->push_back(KeyVal(key, value)); return true; } @@ -169,9 +173,10 @@ struct Parser throw CoreException("Empty tag name"); std::vector<KeyVal>* items; + std::set<std::string> seen; tag = ConfigTag::create(name, current.filename, current.line, items); - while (kv(items)); + while (kv(items, seen)); if (name == "include") { |
