Fix inline comments in dropshell handling
All checks were successful
Build-Test-Publish / build (linux/amd64) (push) Successful in 35s
Build-Test-Publish / build (linux/arm64) (push) Successful in 59s

This commit is contained in:
Your Name
2025-09-20 10:14:28 +12:00
parent 0916953018
commit c8493b92a0
2 changed files with 31 additions and 4 deletions

View File

@@ -35,6 +35,26 @@ bool envmanager::load() {
std::string key = line.substr(0, pos);
std::string value = line.substr(pos + 1);
// Remove inline comments (everything after unquoted #)
bool in_quotes = false;
char quote_char = '\0';
for (size_t i = 0; i < value.length(); ++i) {
char c = value[i];
// Handle quote state changes
if (!in_quotes && (c == '\'' || c == '"')) {
in_quotes = true;
quote_char = c;
} else if (in_quotes && c == quote_char && (i == 0 || value[i-1] != '\\')) {
in_quotes = false;
quote_char = '\0';
} else if (!in_quotes && c == '#') {
// Found unquoted # - truncate value here
value = value.substr(0, i);
break;
}
}
// trim whitespace from the key and value
m_variables[dequote(trim(key))] = dequote(trim(value));
}