fix env variable load and subst order
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user