fix env variable load and subst order
All checks were successful
Build-Test-Publish / build (linux/amd64) (push) Successful in 1m24s
Build-Test-Publish / build (linux/arm64) (push) Successful in 4m16s

This commit is contained in:
2025-10-03 18:56:04 +13:00
parent e001413844
commit af75b0b4ac
13 changed files with 124 additions and 64 deletions

View File

@@ -376,25 +376,24 @@ std::string replace_with_environment_variables_like_bash(std::string str) {
}
std::string substitute_provided_key_value_pairs(std::string str, const std::map<std::string, std::string> &env_vars)
std::string substitute_provided_key_value_pairs(std::string str, const ordered_env_vars& env_vars)
{
// Combined regex pattern for both ${var} and $var formats
std::regex var_pattern("\\$(?:\\{([^}]+)\\}|([a-zA-Z0-9_]+))");
std::string result = str;
std::smatch match;
while (std::regex_search(result, match, var_pattern)) {
// match[1] will contain capture from ${var} format
// match[2] will contain capture from $var format
std::string var_name = match[1].matched ? match[1].str() : match[2].str();
// Get value from environment variables map
auto it = env_vars.find(var_name);
std::string value = (it != env_vars.end()) ? it->second : "";
// Get value from environment variables
std::string value = get_var(env_vars, var_name);
result = result.replace(match.position(), match.length(), value);
}
return result;
}