diff --git a/src/config.cpp b/src/config.cpp index c6492ee..ecefe52 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -513,8 +513,14 @@ CParseResult CConfig::parseVariable(const std::string& lhs, const std::string& r CParseResult CConfig::parseLine(std::string line, bool dynamic) { CParseResult result; - auto commentPos = line.find('#'); - size_t lastHashPos = 0; + line = removeBeginEndSpacesTabs(line); + + auto commentPos = line.find('#'); + + if (commentPos == 0) + return result; + + size_t lastHashPos = 0; while (commentPos != std::string::npos) { bool escaped = false; @@ -536,9 +542,12 @@ CParseResult CConfig::parseLine(std::string line, bool dynamic) { line = removeBeginEndSpacesTabs(line); + if (line.empty()) + return result; + auto equalsPos = line.find('='); - if (equalsPos == std::string::npos && !line.ends_with("{") && line != "}" && !line.empty()) { + if (equalsPos == std::string::npos && !line.ends_with("{") && line != "}") { // invalid line result.setError("Invalid config line"); return result; @@ -607,7 +616,7 @@ CParseResult CConfig::parseLine(std::string line, bool dynamic) { if (ret.error) return ret; - } else if (!line.empty()) { + } else { // has to be a set if (line.contains("}")) { // easiest. } or invalid. diff --git a/tests/config/config.conf b/tests/config/config.conf index f3b018f..243421c 100644 --- a/tests/config/config.conf +++ b/tests/config/config.conf @@ -1,5 +1,10 @@ # Test comment +## This is also a comment + ## This is a comment with space as a first character + ## This is a comment with tab as a first character + ## This is a comment with leading spaces and tabs + ##### Comment with more hash tags testInt = 123 testFloat = 123.456