w41ter commented on code in PR #51199: URL: https://github.com/apache/doris/pull/51199#discussion_r2106449705
########## be/src/common/config.cpp: ########## @@ -1543,23 +1543,65 @@ void splitkv(const std::string& s, std::string& k, std::string& v) { } // replace env variables -bool replaceenv(std::string& s) { - std::size_t pos = 0; - std::size_t start = 0; - while ((start = s.find("${", pos)) != std::string::npos) { - std::size_t end = s.find('}', start + 2); - if (end == std::string::npos) { - return false; +bool replaceenv(std::string key, std::string& s) { + size_t pos = 0; + bool modified = false; + + while (pos < s.size()) { + size_t start = s.find('$', pos); + if (start == std::string::npos) break; + + if (start > 0 && s[start - 1] == '$') { + s.erase(start - 1, 1); + pos = start; + modified = true; + continue; } - std::string envkey = s.substr(start + 2, end - start - 2); - const char* envval = std::getenv(envkey.c_str()); - if (envval == nullptr) { - return false; + + bool has_brace = false; + size_t var_start = start + 1; + size_t end = std::string::npos; + + // format: ${VAR} + if (var_start < s.size() && s[var_start] == '{') { + has_brace = true; + var_start++; + end = s.find('}', var_start); + if (end == std::string::npos) return false; + } else { + // format: $VAR + if (var_start >= s.size()) { + pos = var_start; + continue; + } Review Comment: ```suggestion if (var_start >= s.size()) { break; } ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org