Validate variants.ini syntax
authorFabian Fichter <ianfab@users.noreply.github.com>
Fri, 5 Nov 2021 21:25:39 +0000 (22:25 +0100)
committerFabian Fichter <ianfab@users.noreply.github.com>
Sat, 6 Nov 2021 13:01:47 +0000 (14:01 +0100)
Closes #388.

src/variant.cpp

index 5e3ca67..f6ebc5a 100644 (file)
@@ -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