From ad1a69b975c362aa0e22dc5df97860c3098310b8 Mon Sep 17 00:00:00 2001 From: Fabian Fichter Date: Fri, 5 Nov 2021 22:25:39 +0100 Subject: [PATCH] Validate variants.ini syntax Closes #388. --- src/variant.cpp | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/variant.cpp b/src/variant.cpp index 5e3ca67..f6ebc5a 100644 --- a/src/variant.cpp +++ b/src/variant.cpp @@ -1484,8 +1484,13 @@ void VariantMap::parse_istream(std::istream& file) { while (file.peek() != '[' && std::getline(file, input)) { std::stringstream ss(input); - if (ss.peek() != '#' && std::getline(std::getline(ss, key, '=') >> std::ws, value) && !key.empty()) - attribs[key.erase(key.find_last_not_of(" ") + 1)] = value; + if (ss.peek() != ';' && ss.peek() != '#') + { + if (DoCheck && !input.empty() && input.find('=') == std::string::npos) + std::cerr << "Invalid sytax: '" << input << "'." << std::endl; + if (std::getline(std::getline(ss, key, '=') >> std::ws, value) && !key.empty()) + attribs[key.erase(key.find_last_not_of(" ") + 1)] = value; + } } // Create variant -- 1.7.0.4