]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3141] restore delimiter escaping
authorPiotrek Zadroga <piotrek@isc.org>
Tue, 20 Feb 2024 09:29:09 +0000 (10:29 +0100)
committerPiotrek Zadroga <piotrek@isc.org>
Fri, 23 Feb 2024 16:14:06 +0000 (17:14 +0100)
src/lib/dhcp/option_definition.cc

index 1a0f0d7da42657cc50c71242e37c46dd3e2db312..adb69e85e73f54704056723dd3f6d471e9ff521b 100644 (file)
@@ -33,8 +33,8 @@
 #include <dns/name.h>
 #include <util/strutil.h>
 #include <boost/algorithm/string/classification.hpp>
-#include <boost/algorithm/string/join.hpp>
 #include <boost/algorithm/string/predicate.hpp>
+#include <boost/algorithm/string/replace.hpp>
 #include <boost/dynamic_bitset.hpp>
 #include <boost/make_shared.hpp>
 #include <sstream>
@@ -317,7 +317,24 @@ OptionDefinition::optionFactory(Option::Universe u, uint16_t type,
             // convenient notation option config that needs special parsing. Let's treat it like
             // String type. optionFactory() will be called with convenient_notation flag set to
             // true, so that the factory will have a chance to handle it in a special way.
-            writeToBuffer(u, boost::algorithm::join(values, ","), OPT_STRING_TYPE, buf);
+
+            // At this stage any escape backslash chars were lost during last call of
+            // isc::util::str::tokens(), so we must restore them. Some INTERNAL options may use
+            // escaped delimiters, e.g. DNR options.
+            std::ostringstream stream;
+            bool first = true;
+            for (auto val : values) {
+                boost::algorithm::replace_all(val, ",", "\\,");
+                if (first) {
+                    first = false;
+                } else {
+                    stream << ",";
+                }
+
+                stream << val;
+            }
+
+            writeToBuffer(u, stream.str(), OPT_STRING_TYPE, buf);
         } else {
             writeToBuffer(u, util::str::trim(values[0]), type_, buf);
         }