@@ -107,11 +107,13 @@ static void throw_wrong_format_vec(const char *env_var_name) {
107107 throw std::invalid_argument (ex_ss.str ());
108108}
109109
110- static void throw_wrong_format_map (const char *env_var_name) {
110+ static void throw_wrong_format_map (const char *env_var_name,
111+ std::string env_var_value) {
111112 std::stringstream ex_ss;
112- ex_ss << " Wrong format of the " << env_var_name << " environment variable!"
113- << " Proper format is: "
114- " ENV_VAR=\" param_1:value_1,value_2;param_2:value_1" ;
113+ ex_ss << " Wrong format of the " << env_var_name
114+ << " environment variable value: '" << env_var_value << " '\n "
115+ << " Proper format is: "
116+ " ENV_VAR=\" param_1:value_1,value_2;param_2:value_1\" " ;
115117 throw std::invalid_argument (ex_ss.str ());
116118}
117119
@@ -188,31 +190,42 @@ inline std::optional<EnvVarMap> getenv_to_map(const char *env_var_name,
188190 return std::nullopt ;
189191 }
190192
193+ auto is_quoted = [](std::string &str) {
194+ return (str.front () == ' \' ' && str.back () == ' \' ' ) ||
195+ (str.front () == ' "' && str.back () == ' "' );
196+ };
197+ auto has_colon = [](std::string &str) {
198+ return str.find (' :' ) != std::string::npos;
199+ };
200+
191201 std::stringstream ss (*env_var);
192202 std::string key_value;
193203 while (std::getline (ss, key_value, main_delim)) {
194204 std::string key;
195205 std::string values;
196206 std::stringstream kv_ss (key_value);
197207
198- if (reject_empty && key_value. find ( ' : ' ) == std::string::npos ) {
199- throw_wrong_format_map (env_var_name);
208+ if (reject_empty && ! has_colon (key_value) ) {
209+ throw_wrong_format_map (env_var_name, *env_var );
200210 }
201211
202212 std::getline (kv_ss, key, key_value_delim);
203213 std::getline (kv_ss, values);
204214 if (key.empty () || (reject_empty && values.empty ()) ||
205- values.find (' :' ) != std::string::npos ||
206215 map.find (key) != map.end ()) {
207- throw_wrong_format_map (env_var_name);
216+ throw_wrong_format_map (env_var_name, *env_var );
208217 }
209218
210219 std::vector<std::string> values_vec;
211220 std::stringstream values_ss (values);
212221 std::string value;
213222 while (std::getline (values_ss, value, values_delim)) {
214- if (value.empty ()) {
215- throw_wrong_format_map (env_var_name);
223+ if (value.empty () || (has_colon (value) && !is_quoted (value))) {
224+ throw_wrong_format_map (env_var_name, *env_var);
225+ }
226+ if (is_quoted (value)) {
227+ value.erase (value.cbegin ());
228+ value.pop_back ();
216229 }
217230 values_vec.push_back (value);
218231 }
0 commit comments