Skip to content

Commit 75426ae

Browse files
committed
Fix: OptionStringContainer::to_string delimiter and implement escaping
The methods to_string() and get_value_string() in OptionStringContainer were incorrectly using the hardcoded delimiter ", ". This commit fixes two issues: 1. Delimiter Usage - The methods now use the first defined delimiter instead of the hardcoded ", ". 2. Escaping - Delimiters that are part of the value are now escaped with a backslash '\'.
1 parent c6a42c2 commit 75426ae

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

libdnf5/conf/option_string_list.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -297,17 +297,28 @@ void OptionStringContainer<T, IsAppend>::add_item(Priority priority, const std::
297297

298298
template <typename T, bool IsAppend>
299299
std::string OptionStringContainer<T, IsAppend>::to_string(const ValueType & value) const {
300-
std::ostringstream oss;
300+
std::string result;
301+
302+
const std::string_view delimiters{get_delimiters()};
303+
301304
bool next{false};
302-
for (auto & val : value) {
305+
for (auto & item : value) {
303306
if (next) {
304-
oss << ", ";
307+
if (!delimiters.empty()) {
308+
result += delimiters[0];
309+
}
305310
} else {
306311
next = true;
307312
}
308-
oss << val;
313+
for (const auto ch : item) {
314+
if (delimiters.find(ch) != delimiters.npos) {
315+
result += '\\';
316+
}
317+
result += ch;
318+
}
309319
}
310-
return oss.str();
320+
321+
return result;
311322
}
312323

313324
template <typename T, bool IsAppend>
@@ -332,7 +343,7 @@ inline std::string OptionStringContainer<T, IsAppend>::get_value_string() const
332343

333344
template <typename T, bool IsAppend>
334345
inline const char * OptionStringContainer<T, IsAppend>::get_default_delimiters() noexcept {
335-
return " ,\n";
346+
return ", \n";
336347
}
337348

338349
template <typename T, bool IsAppend>

0 commit comments

Comments
 (0)